using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Sunweaver.Commands; using Sunweaver.VM; namespace Sunweaver.UnitTesting.Commands { public class branchTests : UnitTestSharp.TestFixture { BasePair bp = new branch(); VirtualMachine VM; Codule codule; public override void TestSetup() { VM = new VirtualMachine(); codule = new Codule(); codule.BasePairs.Add(bp); } public void Basic() { VM.Stack.Push(77); VM.CallingChromosome = new Chromosome(new[] { codule }); VM.CallingChromosome.Codules.Add(77, new Codule(new BasePair[] { new Constant(10) })); codule.Execute(VM); CheckEqual(1, VM.Stack.Count()); CheckEqual(10, VM.Stack.Pop()); } public void Negative() { VM.Stack.Push(-77); VM.CallingChromosome = new Chromosome(new[] { codule }); VM.CallingChromosome.Codules.Add(77, new Codule(new BasePair[] { new Constant(10) })); codule.Execute(VM); CheckEqual(1, VM.Stack.Count()); CheckEqual(10, VM.Stack.Pop()); } public void HighIndexModulus() { VM.Stack.Push(10077); VM.CallingChromosome = new Chromosome(new[] { codule }); VM.CallingChromosome.Codules.Add(77, new Codule(new BasePair[] { new Constant(10) })); codule.Execute(VM); CheckEqual(1, VM.Stack.Count()); CheckEqual(10, VM.Stack.Pop()); } public void NegativeHighIndexModulus() { VM.Stack.Push(-10077); VM.CallingChromosome = new Chromosome(new[] { codule }); VM.CallingChromosome.Codules.Add(77, new Codule(new BasePair[] { new Constant(10) })); codule.Execute(VM); CheckEqual(1, VM.Stack.Count()); CheckEqual(10, VM.Stack.Pop()); } public void FalseOnBoolStack() { VM.BoolStack.Push(false); VM.Stack.Push(77); VM.CallingChromosome = new Chromosome(new[] { codule }); VM.CallingChromosome.Codules.Add(77, new Codule(new BasePair[] { new Constant(10) })); codule.Execute(VM); CheckEqual(0, VM.Stack.Count()); } public void NoRecursion() { VM.Stack.Push(77); VM.CallingChromosome = new Chromosome(new[] { codule }); VM.CallingChromosome.Codules.Add(77, new Codule(new BasePair[] { new Label("", 10), new Label("", 77), new branch(), })); codule.Execute(VM); CheckEqual(1, VM.Stack.Count()); CheckEqual(10, VM.Stack.Pop()); } public void CanbranchTwice() { VM.Stack.Push(77); codule.BasePairs.Add(new Constant(77)); codule.BasePairs.Add(new branch()); VM.CallingChromosome = new Chromosome(new[] { codule }); VM.CallingChromosome.Codules.Add(77, new Codule(new BasePair[] { new Label("", 10), })); codule.Execute(VM); CheckEqual(2, VM.Stack.Count()); CheckEqual(10, VM.Stack.Pop()); CheckEqual(10, VM.Stack.Pop()); } public void AbortsOnNoArguemnts() { VM.CallingChromosome = new Chromosome(new[] { codule }); VM.CallingChromosome.Codules.Add(77, new Codule(new BasePair[] { new Label("", 10), new Label("", 77), new branch(), })); codule.Execute(VM); CheckEqual(0, VM.Stack.Count()); } public void NoRepeatsInbranchstack() { VM.Stack.Push(77); VM.CallingChromosome = new Chromosome(new[] { codule }); VM.CallingChromosome.Codules.Add(77, new Codule(new BasePair[] { new Constant(10), new Constant(33), new branch(), })); VM.CallingChromosome.Codules.Add(33, new Codule(new BasePair[] { new Constant(11), new Constant(77), new branch(), })); codule.Execute(VM); CheckEqual(2, VM.Stack.Count()); CheckEqual(11, VM.Stack.Pop()); CheckEqual(10, VM.Stack.Pop()); } public void NameTest() { CheckEqual("branch", bp.ToString()); } } }