forked from lightszero/LSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
增加覆盖ToString,GetHashCode,Equals方法的测试用例
bug: 目前这三个方法都是调用CLRSharp_Instance的方法
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
| ||
using UnitTest; | ||
|
||
/// <summary> | ||
/// 测试覆盖系统方法 | ||
/// </summary> | ||
public class Test12 | ||
{ | ||
public string Name; | ||
public int Age; | ||
|
||
public override string ToString() | ||
{ | ||
return string.Format("Name:{0}, Age:{1}", Name, Age); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (!(obj is Test12)) | ||
{ | ||
return false; | ||
} | ||
var o = (Test12) obj; | ||
return Name == o.Name && Age == o.Age; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
//for test | ||
return 123456789; | ||
} | ||
|
||
public static void TestOverrideObjectMethod() | ||
{ | ||
Test12 t1 = new Test12 {Name = "Test1", Age = 18}; | ||
Test12 t2 = new Test12 {Name = "Test1", Age = 18}; | ||
|
||
Logger.Log("t1.ToString(): " + t1); | ||
Logger.Log("t1.GetHashCode(): " + t1.GetHashCode()); | ||
Logger.Log("t1.Equals(t2): " + t1.Equals(t2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters