using System; using System.Collections.Generic; using System.Text; using UnitTestSharp; using Sunweaver.Commands.Abstracts; using Sunweaver.Commands; using Sunweaver.VM; namespace Sunweaver.UnitTesting.Commands { public class randTest : TestFixture { BasePair bp = new rand(); VirtualMachine VM; public override void TestSetup() { VM = new VirtualMachine(); } public void TestRandom() { for (int i = 0; i < 100; i++) { VM.Stack.Push(10); bp.Implementation(VM); var result = VM.Stack.Pop(); Check(result >= 1 && result <= 10); } } public void TestNegativeRandom() { for (int i = 0; i < 100; i++) { VM.Stack.Push(-10); bp.Implementation(VM); var result = VM.Stack.Pop(); Check(result <= -1 && result >= -10); } } public void Test0() { for (int i = 0; i < 100; i++) { VM.Stack.Push(0); bp.Implementation(VM); var result = VM.Stack.Pop(); CheckEqual(0, result); } } public void Test1() { for (int i = 0; i < 100; i++) { VM.Stack.Push(1); bp.Implementation(VM); var result = VM.Stack.Pop(); CheckEqual(1, result); } } public void TestNeg1() { for (int i = 0; i < 100; i++) { VM.Stack.Push(-1); bp.Implementation(VM); var result = VM.Stack.Pop(); CheckEqual(-1, result); } } public void CheckFullRange() { bool[] found = {false, false, false, false}; for (int i = 0; i < 100; i++) { VM.Stack.Push(3); bp.Implementation(VM); found[VM.Stack.Pop()] = true; } CheckEqual(new bool[] { false, true, true, true }, found); } } }