public void RandShouldAlwaysReturnRandomNumbers() { var hashSet = new HashSet<int>(); var cpu = new Cpu32(2); var motherboardMock = new Mock<IMotherboard>(); cpu.AttachTo(motherboardMock.Object); motherboardMock.Setup(x => x.SaveRamValue(It.IsAny<int>())) .Callback<int>(z => hashSet.Add(z)); for (int i = 0; i < 10000; i++) { cpu.Rand(1, 10); } Assert.AreEqual(10, hashSet.Count); }
public void RandShouldNotProduceNumbersGreaterThanMaxValue() { var cpu = new Cpu32(2); var motherboardMock = new Mock<IMotherboard>(); cpu.AttachTo(motherboardMock.Object); var globalMax = int.MinValue; motherboardMock.Setup(x => x.SaveRamValue(It.IsAny<int>())) .Callback<int>(z => globalMax = Math.Max(globalMax, z)); for (int i = 0; i < 10000; i++) { cpu.Rand(1, 10); } Assert.AreEqual(10, globalMax); }