forked from CosmosOS/Cosmos
-
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.
- Loading branch information
1 parent
559ee85
commit c12022c
Showing
13 changed files
with
488 additions
and
315 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Cosmos.TestRunner; | ||
|
||
namespace SimpleStructsAndArraysTest | ||
{ | ||
public interface ITestMutate | ||
{ | ||
void Mutate(); | ||
} | ||
|
||
public struct MyStruct1 : ITestMutate | ||
{ | ||
public int a; | ||
|
||
public void Mutate() | ||
{ | ||
a++; | ||
} | ||
} | ||
|
||
public struct MyStruct2 | ||
{ | ||
public int b; | ||
|
||
public override string ToString() | ||
{ | ||
b++; | ||
return b.ToString(); | ||
} | ||
} | ||
|
||
internal struct MyStruct3 | ||
{ | ||
public int c; | ||
|
||
public override string ToString() | ||
{ | ||
c = 1; | ||
return c.ToString(); | ||
} | ||
} | ||
|
||
public static class ConstrainedTest | ||
{ | ||
public static void DoMutate<T>(ref T a) where T : ITestMutate | ||
{ | ||
a.Mutate(); | ||
} | ||
|
||
public static void MutateStructTest() | ||
{ | ||
var xS1 = new MyStruct1(); | ||
Assert.IsTrue(xS1.a == 0, "xS1.a == 0"); | ||
DoMutate(ref xS1); | ||
Assert.IsTrue(xS1.a == 1, "xS1.a == 1"); | ||
|
||
var xS2 = new MyStruct2(); | ||
Assert.IsTrue(xS2.b == 0, "xS2.b == 0"); | ||
Assert.IsTrue(xS2.ToString() == "1", "xS2.ToString() == '1'"); | ||
Assert.IsTrue(xS2.b == 1, "xS2.b == 1"); | ||
|
||
var xS3 = new MyStruct3(); | ||
Assert.IsTrue(xS3.c == 0, "xS3.b == 0"); | ||
Assert.IsTrue(xS3.ToString() == "1", "xS3.ToString() == '1'"); | ||
Assert.IsTrue(xS3.c == 1, "xS3.b == 1"); | ||
} | ||
} | ||
} |
Oops, something went wrong.