using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Sunweaver.Commands.Abstracts; using Sunweaver.VM; using Sunweaver.Commands; namespace Sunweaver.UnitTesting.Commands { public class ExplicitBranchTests : UnitTestSharp.TestFixture { BasePair bp = new ExplicitBranch("Name", 77); VirtualMachine VM; Codule codule; public override void TestSetup() { VM = new VirtualMachine(); codule = new Codule(); codule.BasePairs.Add(bp); } public void Basic() { 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.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.CallingChromosome = new Chromosome(new[] { codule }); VM.CallingChromosome.Codules.Add(77, new Codule(new BasePair[] { new Label("", 10), new ExplicitBranch("", 77), })); codule.Execute(VM); CheckEqual(1, VM.Stack.Count()); CheckEqual(10, VM.Stack.Pop()); } public void NoRepeatsInCallstack() { VM.CallingChromosome = new Chromosome(new[] { codule }); VM.CallingChromosome.Codules.Add(77, new Codule(new BasePair[] { new Constant(10), new ExplicitBranch("", 33), })); VM.CallingChromosome.Codules.Add(33, new Codule(new BasePair[] { new Constant(11), new ExplicitBranch("", 77), })); codule.Execute(VM); CheckEqual(2, VM.Stack.Count()); CheckEqual(11, VM.Stack.Pop()); CheckEqual(10, VM.Stack.Pop()); } public void NameTest() { CheckEqual("?Name", bp.ToString()); } } }