mirror of
https://github.com/Smaug123/WoofWare.PawPrint
synced 2025-10-12 00:58:39 +00:00
Implement shl, shr, or (#82)
This commit is contained in:
@@ -16,6 +16,18 @@ module TestPureCases =
|
||||
|
||||
let unimplemented =
|
||||
[
|
||||
{
|
||||
FileName = "TestShl.cs"
|
||||
ExpectedReturnCode = 0
|
||||
NativeImpls = MockEnv.make ()
|
||||
LocalVariablesOfMain = None
|
||||
}
|
||||
{
|
||||
FileName = "TestShr.cs"
|
||||
ExpectedReturnCode = 0
|
||||
NativeImpls = MockEnv.make ()
|
||||
LocalVariablesOfMain = None
|
||||
}
|
||||
{
|
||||
FileName = "Threads.cs"
|
||||
ExpectedReturnCode = 3
|
||||
@@ -100,18 +112,9 @@ module TestPureCases =
|
||||
}
|
||||
{
|
||||
FileName = "ArgumentOrdering.cs"
|
||||
ExpectedReturnCode = 42
|
||||
ExpectedReturnCode = 0
|
||||
NativeImpls = MockEnv.make ()
|
||||
LocalVariablesOfMain =
|
||||
[
|
||||
// localVar
|
||||
CliType.Numeric (CliNumericType.Int32 42)
|
||||
// t
|
||||
CliType.ValueType [ CliType.Numeric (CliNumericType.Int32 42) ]
|
||||
// return value
|
||||
CliType.Numeric (CliNumericType.Int32 42)
|
||||
]
|
||||
|> Some
|
||||
LocalVariablesOfMain = None
|
||||
}
|
||||
{
|
||||
FileName = "BasicLock.cs"
|
||||
@@ -197,6 +200,12 @@ module TestPureCases =
|
||||
NativeImpls = MockEnv.make ()
|
||||
LocalVariablesOfMain = None
|
||||
}
|
||||
{
|
||||
FileName = "TestOr.cs"
|
||||
ExpectedReturnCode = 0
|
||||
NativeImpls = MockEnv.make ()
|
||||
LocalVariablesOfMain = None
|
||||
}
|
||||
]
|
||||
|
||||
[<TestCaseSource(nameof cases)>]
|
||||
|
@@ -31,6 +31,9 @@
|
||||
<EmbeddedResource Include="sourcesPure\Threads.cs" />
|
||||
<EmbeddedResource Include="sourcesPure\ResizeArray.cs" />
|
||||
<EmbeddedResource Include="sourcesPure\ArgumentOrdering.cs" />
|
||||
<EmbeddedResource Include="sourcesPure\TestShl.cs" />
|
||||
<EmbeddedResource Include="sourcesPure\TestShr.cs" />
|
||||
<EmbeddedResource Include="sourcesPure\TestOr.cs" />
|
||||
<EmbeddedResource Include="sourcesPure\CustomDelegate.cs" />
|
||||
<EmbeddedResource Include="sourcesPure\Ldind.cs" />
|
||||
</ItemGroup>
|
||||
|
@@ -10,10 +10,40 @@ public class Program
|
||||
}
|
||||
}
|
||||
|
||||
public struct Calculator
|
||||
{
|
||||
private int baseValue;
|
||||
|
||||
public Calculator(int initial)
|
||||
{
|
||||
baseValue = initial;
|
||||
}
|
||||
|
||||
public int Add(int a, int b, int c)
|
||||
{
|
||||
return baseValue + a + b + c;
|
||||
}
|
||||
|
||||
public int SubtractIsh(int a, int b)
|
||||
{
|
||||
return baseValue - a + b;
|
||||
}
|
||||
}
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
int localVar = 42;
|
||||
TestStruct t = new TestStruct(ref localVar);
|
||||
return t.Value;
|
||||
if (t.Value != 42) return 1;
|
||||
|
||||
Calculator calc = new Calculator(10);
|
||||
int addResult = calc.Add(1, 2, 3); // Should be 10 + 1 + 2 + 3 = 16
|
||||
if (addResult != 16) return 2;
|
||||
|
||||
// Test 2: Verify order matters
|
||||
int subResult = calc.SubtractIsh(3, 2); // Should be 10 - 3 + 2 = 9
|
||||
if (subResult != 9) return 3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
41
WoofWare.PawPrint.Test/sourcesPure/TestOr.cs
Normal file
41
WoofWare.PawPrint.Test/sourcesPure/TestOr.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
public class TestOr
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
// Test 1: Bitwise OR with Int32
|
||||
int a32 = 12; // Binary: 1100
|
||||
int b32 = 10; // Binary: 1010
|
||||
int result32 = a32 | b32; // Should be 14 (Binary: 1110)
|
||||
if (result32 != 14) return 1;
|
||||
|
||||
// Test 2: Bitwise OR with Int64
|
||||
long a64 = 0x00FF00FFL;
|
||||
long b64 = 0xFF00FF00L;
|
||||
long result64 = a64 | b64;
|
||||
if (result64 != 0xFFFFFFFFL) return 2;
|
||||
|
||||
// Test 3: Mixed bitwise OR (Int32 and native int)
|
||||
int aMixed = 15; // Binary: 1111
|
||||
nint bMixed = 240; // Binary: 11110000
|
||||
nint resultMixed = aMixed | bMixed; // Should be 255 (Binary: 11111111)
|
||||
if (resultMixed != 255) return 3;
|
||||
|
||||
// Test 4: OR with itself
|
||||
int self = 42;
|
||||
int selfResult = self | self;
|
||||
if (selfResult != 42) return 4;
|
||||
|
||||
// Test 5: OR with 0
|
||||
int withZero = 123;
|
||||
int zeroResult = withZero | 0;
|
||||
if (zeroResult != 123) return 5;
|
||||
|
||||
// Test 6: Native int OR native int
|
||||
nint nativeA = 0x0F;
|
||||
nint nativeB = 0xF0;
|
||||
nint nativeResult = nativeA | nativeB; // Should be 0xFF
|
||||
if (nativeResult != 0xFF) return 6;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
34
WoofWare.PawPrint.Test/sourcesPure/TestShl.cs
Normal file
34
WoofWare.PawPrint.Test/sourcesPure/TestShl.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
public class TestShl
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
// Test 1: Shift Left with Int32
|
||||
int value32 = 5; // Binary: 0101
|
||||
int shift32 = 2;
|
||||
int result32 = value32 << shift32; // Should be 20 (Binary: 10100)
|
||||
if (result32 != 20) return 1;
|
||||
|
||||
// Test 2: Shift Left with Int64
|
||||
long value64 = 7L; // Binary: 0111
|
||||
int shift64 = 3;
|
||||
long result64 = value64 << shift64; // Should be 56 (Binary: 111000)
|
||||
if (result64 != 56L) return 2;
|
||||
|
||||
// Test 3: Shift by 0
|
||||
int noShiftValue = 42;
|
||||
int noShiftResult = noShiftValue << 0;
|
||||
if (noShiftResult != 42) return 3;
|
||||
|
||||
// Test 4: Shift by 1
|
||||
int singleShiftResult = noShiftValue << 1;
|
||||
if (singleShiftResult != 84) return 4;
|
||||
|
||||
// Test 5: Shift with native int
|
||||
nint nativeValue = 3;
|
||||
int nativeShift = 4;
|
||||
nint nativeResult = nativeValue << nativeShift; // Should be 48
|
||||
if (nativeResult != 48) return 5;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
35
WoofWare.PawPrint.Test/sourcesPure/TestShr.cs
Normal file
35
WoofWare.PawPrint.Test/sourcesPure/TestShr.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
public class TestShr
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
// Test 1: Shift Right with Int32
|
||||
int value32 = 20; // Binary: 10100
|
||||
int shift32 = 2;
|
||||
int result32 = value32 >> shift32; // Should be 5 (Binary: 0101)
|
||||
if (result32 != 5) return 1;
|
||||
|
||||
// Test 2: Shift Right with Int64
|
||||
long value64 = 56L; // Binary: 111000
|
||||
int shift64 = 3;
|
||||
long result64 = value64 >> shift64; // Should be 7 (Binary: 0111)
|
||||
if (result64 != 7L) return 2;
|
||||
|
||||
// Test 3: Right shift preserving sign (negative number)
|
||||
int negative = -16;
|
||||
int negativeResult = negative >> 2; // Should be -4
|
||||
if (negativeResult != -4) return 3;
|
||||
|
||||
// Test 4: Shift by 0
|
||||
int noShiftValue = 99;
|
||||
int noShiftResult = noShiftValue >> 0;
|
||||
if (noShiftResult != 99) return 4;
|
||||
|
||||
// Test 5: Shift with native int
|
||||
nint nativeValue = 48;
|
||||
int nativeShift = 4;
|
||||
nint nativeResult = nativeValue >> nativeShift; // Should be 3
|
||||
if (nativeResult != 3) return 5;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user