static void AssertDivMod(int x1, int x2) { var nd = SchemeImpl.Div(x1, x2); var xm = SchemeImpl.Mod(x1, x2); AssertDivMod(x1, x2, nd, xm); }
static void AssertDivMod(int x1, int x2) { var nd = SchemeImpl.Div(x1, x2); var xm = SchemeImpl.Mod(x1, x2); var r = SchemeImpl.DivMod(x1, x2); Assert.AreEqual(nd, r.Item1); Assert.AreEqual(xm, r.Item2); AssertDivMod(x1, x2, nd, xm); }
static void Main(string[] args) { var sw = new Stopwatch(); var r = SchemeImpl.Div(123, 10); for (int i = 0; i < 500000; i++) { r = SchemeImpl.Div(123, 10); //r = SchemeImpl.DivSlow(123, 10); r = SchemeImpl.Div0(123, 10); //r = SchemeImpl.Div0Slow(123, 10); } const int MAX = 500000000; sw.Start(); for (int i = 1; i < MAX; i++) { r = SchemeImpl.Div(i, MAX - i); r = SchemeImpl.Div(i, 0 - i); r = SchemeImpl.Div(MAX - i, i); r = SchemeImpl.Div(0 - i, i); } sw.Stop(); Console.WriteLine("Div: {0:f3}s", sw.Elapsed.TotalSeconds); /* * sw.Restart(); * * for (int i = 1; i < MAX; i++) * { * r = SchemeImpl.DivSlow(i, 0 - i); * } * * sw.Stop(); * * Console.WriteLine("DivSlow: {0:f3}s", sw.Elapsed.TotalSeconds); */ sw.Restart(); for (int i = 1; i < MAX; i++) { r = SchemeImpl.Div0(i, MAX - i); r = SchemeImpl.Div0(i, 0 - i); r = SchemeImpl.Div0(MAX - i, i); r = SchemeImpl.Div0(0 - i, i); } sw.Stop(); Console.WriteLine("Div0: {0:f3}s", sw.Elapsed.TotalSeconds); /* * sw.Restart(); * * for (int i = 1; i < MAX; i++) * { * r = SchemeImpl.Div0Slow(i, 0 - i); * } * * sw.Stop(); * * Console.WriteLine("Div0Slow: {0:f3}s", sw.Elapsed.TotalSeconds); */ Console.WriteLine(r); }
public void TestDivPP() { Assert.AreEqual(12, SchemeImpl.Div(123, 10)); }
public void TestDivNN() { Assert.AreEqual(13, SchemeImpl.Div(-123, -10)); }
public void TestDivNP() { Assert.AreEqual(-13, SchemeImpl.Div(-123, 10)); }
public void TestDivPN() { Assert.AreEqual(-12, SchemeImpl.Div(123, -10)); }
public void TestDivPP() { Assert.AreEqual(1, SchemeImpl.Div(17, 11)); }
public void TestDivNN() { Assert.AreEqual(2, SchemeImpl.Div(-17, -11)); }
public void TestDivNP() { Assert.AreEqual(-2, SchemeImpl.Div(-17, 11)); }
public void TestDivPN() { Assert.AreEqual(-1, SchemeImpl.Div(17, -11)); }