public void AddFrameTest() { // test case 1 (Add 11 frames, which is less than target_legnth_max, then add another frame) FrameManager fm = new FrameManager(10); for (int i = 0; i < 11; ++i) { Frame newF = new Frame { frameId = i + 1, frameResource = "Placeholder Content" }; fm.AddFrame(newF); } var actual = fm.StoredFrameCount; var expect = 11; Assert.AreEqual(expect, actual); // Add a frame fm.AddFrame(new Frame { frameId = 12, frameResource = "Placeholder Content" }); actual = fm.StoredFrameCount; expect = 12; Assert.AreEqual(expect, actual); // test case 2 (Add number of frames equal to target_length_max) fm = new FrameManager(5); for (int i = 0; i < 6; ++i) { Frame newF = new Frame { frameId = i + 1, frameResource = "Placeholder Content" }; fm.AddFrame(newF); } actual = fm.StoredFrameCount; expect = 6; Assert.AreEqual(expect, actual); // test case 3, Add number of frames larger than target_length_max fm = new FrameManager(5); for (int i = 0; i < 7; ++i) { Frame newF = new Frame { frameId = i + 1, frameResource = "Placeholder Content" }; fm.AddFrame(newF); } actual = fm.StoredFrameCount; expect = 4; Assert.AreEqual(expect, actual); }
public void GetFrameTest() { // multiple tests simulating different usage scenarios var fm = new FrameManager(5); for (int i = 0; i < 9; ++i) { Frame newF = new Frame { frameId = i + 1, frameResource = "Placeholder Content" }; fm.AddFrame(newF); Frame[] expect; Frame[] actual; if (i + 1 == 6) { expect = new Frame[6] { new Frame { frameId = 1, frameResource = "Placeholder Content" }, new Frame { frameId = 2, frameResource = "Placeholder Content" }, new Frame { frameId = 3, frameResource = "Placeholder Content" }, new Frame { frameId = 4, frameResource = "Placeholder Content" }, new Frame { frameId = 5, frameResource = "Placeholder Content" }, new Frame { frameId = 6, frameResource = "Placeholder Content" } }; actual = (Frame[])fm.GetFrame(); CollectionAssert.AreEqual(expect, actual); } else if (i + 1 == 7) { expect = new Frame[4] { new Frame { frameId = 1, frameResource = "Placeholder Content" }, new Frame { frameId = 3, frameResource = "Placeholder Content" }, new Frame { frameId = 5, frameResource = "Placeholder Content" }, new Frame { frameId = 7, frameResource = "Placeholder Content" } }; actual = (Frame[])fm.GetFrame(); CollectionAssert.AreEqual(expect, actual); } else if (i + 1 == 9) { expect = new Frame[5] { new Frame { frameId = 1, frameResource = "Placeholder Content" }, new Frame { frameId = 3, frameResource = "Placeholder Content" }, new Frame { frameId = 5, frameResource = "Placeholder Content" }, new Frame { frameId = 7, frameResource = "Placeholder Content" }, new Frame { frameId = 9, frameResource = "Placeholder Content" } }; actual = (Frame[])fm.GetFrame(); CollectionAssert.AreEqual(expect, actual); } } // another test case with different target_length fm = new FrameManager(3); for (int i = 0; i < 9; ++i) { Frame newF = new Frame { frameId = i + 1, frameResource = "Placeholder Content" }; fm.AddFrame(newF); Frame[] expect; Frame[] actual; if (i + 1 == 3) { expect = new Frame[3] { new Frame { frameId = 1, frameResource = "Placeholder Content" }, new Frame { frameId = 2, frameResource = "Placeholder Content" }, new Frame { frameId = 3, frameResource = "Placeholder Content" } }; actual = (Frame[])fm.GetFrame(); CollectionAssert.AreEqual(expect, actual); } else if (i + 1 == 4) { expect = new Frame[4] { new Frame { frameId = 1, frameResource = "Placeholder Content" }, new Frame { frameId = 2, frameResource = "Placeholder Content" }, new Frame { frameId = 3, frameResource = "Placeholder Content" }, new Frame { frameId = 4, frameResource = "Placeholder Content" } }; actual = (Frame[])fm.GetFrame(); CollectionAssert.AreEqual(expect, actual); } else if (i + 1 == 5) { expect = new Frame[3] { new Frame { frameId = 1, frameResource = "Placeholder Content" }, new Frame { frameId = 3, frameResource = "Placeholder Content" }, new Frame { frameId = 5, frameResource = "Placeholder Content" } }; actual = (Frame[])fm.GetFrame(); CollectionAssert.AreEqual(expect, actual); } else if (i + 1 == 6) { expect = new Frame[3] { new Frame { frameId = 1, frameResource = "Placeholder Content" }, new Frame { frameId = 3, frameResource = "Placeholder Content" }, new Frame { frameId = 5, frameResource = "Placeholder Content" } }; actual = (Frame[])fm.GetFrame(); CollectionAssert.AreEqual(expect, actual); } else if (i + 1 == 7) { expect = new Frame[4] { new Frame { frameId = 1, frameResource = "Placeholder Content" }, new Frame { frameId = 3, frameResource = "Placeholder Content" }, new Frame { frameId = 5, frameResource = "Placeholder Content" }, new Frame { frameId = 7, frameResource = "Placeholder Content" } }; actual = (Frame[])fm.GetFrame(); CollectionAssert.AreEqual(expect, actual); } else if (i + 1 == 9) { expect = new Frame[3] { new Frame { frameId = 1, frameResource = "Placeholder Content" }, new Frame { frameId = 5, frameResource = "Placeholder Content" }, new Frame { frameId = 9, frameResource = "Placeholder Content" } }; actual = (Frame[])fm.GetFrame(); CollectionAssert.AreEqual(expect, actual); } } }