public void AddLargeNumTest() { CPU target = new CPU(); string[] codelines = new string[] { // 2000 + 100*250 "LOAD R0,2000", "ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250", "ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250", "ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250", "ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250", "ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250", "ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250", "ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250", "ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250", "ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250", "ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250","ADD 250" }; int startAddress = 0; target.LoadMemory(codelines, startAddress); target.Run(startAddress); Assert.AreEqual(27000, target.GetRegisterValue(0)); }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] public void MyTestInitialize() { CPU cpu = new CPU(); }
public void AddNegNumTest() { CPU target = new CPU(); string[] codelines = new string[] { "LOAD R0,-500", "ADD 250" }; int startAddress = 0; target.LoadMemory(codelines, startAddress); Assert.AreNotEqual(0, target.Memory.GetWord(0).UValue); Assert.AreNotEqual(0, target.Memory.GetWord(2).UValue); Assert.AreEqual(0, target.Memory.GetWord(4).UValue); target.Run(startAddress); Assert.AreEqual(-250, target.GetRegisterValue(0)); }
public void ReadPgmTestFileNotFound() { CPU target = new CPU(); string fullFilename = "FileNotExist.cpu"; string[] actual; try { actual = target.ReadPgm(fullFilename); Assert.Fail("fileNotFoundException exptected"); } catch (FileNotFoundException) { Assert.IsTrue(true); } }
public void ReadPgmTestFileExtNotSupported() { CPU target = new CPU(); string fullFilename = "FileNotExist.txt"; string[] actual; try { actual = target.ReadPgm(fullFilename); Assert.Fail("FileExtention not supported"); } catch (CPUException) { Assert.IsTrue(true); } }
public void LoadMemoryTest() { CPU target = new CPU(); string[] codelines = new string[] { "ADD R1", "ADD 500", "ADD R2" }; int startAddress = 0; target.LoadMemory(codelines, startAddress); Assert.AreNotEqual(0, target.Memory.GetWord(0).UValue); // ADD R1 Assert.AreNotEqual(0, target.Memory.GetWord(2).UValue); // ADD 500 Assert.AreNotEqual(0, target.Memory.GetWord(4).UValue); // ADD R2 Assert.AreEqual(0, target.Memory.GetWord(6).UValue); }