00001
00002
00003 namespace Tests
00004 {
00005 using System;
00006 using Microsoft.VisualStudio.TestTools.UnitTesting;
00007 using NewGamePhysics.Utilities;
00008
00012 [TestClass]
00013 public class UnitTestAutorange
00014 {
00015 public UnitTestAutorange()
00016 {
00017 }
00018
00019 private TestContext testContextInstance;
00020
00025 public TestContext TestContext
00026 {
00027 get
00028 {
00029 return testContextInstance;
00030 }
00031 set
00032 {
00033 testContextInstance = value;
00034 }
00035 }
00036
00037 #region Additional test attributes
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #endregion
00058
00059 [TestMethod]
00060 public void GetSnapValueIsGreater()
00061 {
00062 double[] value = {
00063 0.0,
00064 0.00131,
00065 0.12,
00066 0.2,
00067 0.49,
00068 0.51,
00069 0.75,
00070 10.75,
00071 31123,
00072 -0.00012,
00073 -0.12,
00074 -0.2,
00075 -0.49,
00076 -0.51,
00077 -0.75,
00078 -1.0,
00079 -10.75,
00080 };
00081
00082 double[] expected = {
00083 0.0,
00084 0.002,
00085 0.2,
00086 0.2,
00087 0.5,
00088 1.0,
00089 1.0,
00090 20.0,
00091 50000,
00092 -0.0001,
00093 -0.1,
00094 -0.2,
00095 -0.2,
00096 -0.5,
00097 -0.5,
00098 -1.0,
00099 -10.0
00100 };
00101
00102 for (int i = 0; i < value.Length; i++)
00103 {
00104 double snapValue = Autorange.GetSnapValue(value[i], true);
00105 Console.WriteLine(
00106 "Autorange.GetSnapValue({0}, true): expected {1} got {2}",
00107 value[i],
00108 expected[i],
00109 snapValue);
00110 Assert.AreEqual(expected[i], snapValue);
00111 }
00112 }
00113
00114 [TestMethod]
00115 public void GetSnapValueIsLess()
00116 {
00117 double[] value = {
00118 0.0,
00119 0.00131,
00120 0.12,
00121 0.2,
00122 0.49,
00123 0.51,
00124 0.75,
00125 10.75,
00126 31123,
00127 -0.00012,
00128 -0.12,
00129 -0.2,
00130 -0.49,
00131 -0.51,
00132 -0.75,
00133 -1.0,
00134 -10.75,
00135 };
00136
00137 double[] expected = {
00138 0.0,
00139 0.001,
00140 0.1,
00141 0.1,
00142 0.2,
00143 0.5,
00144 0.5,
00145 10.0,
00146 20000,
00147 -0.0002,
00148 -0.2,
00149 -0.5,
00150 -0.5,
00151 -1.0,
00152 -1.0,
00153 -2.0,
00154 -20.0
00155 };
00156
00157 for (int i = 0; i < value.Length; i++)
00158 {
00159 double snapValue = Autorange.GetSnapValue(value[i], false);
00160 Console.WriteLine(
00161 "Autorange.GetSnapValue({0}, false): expected {1} got {2}",
00162 value[i],
00163 expected[i],
00164 snapValue);
00165 Assert.AreEqual(expected[i], snapValue);
00166 }
00167 }
00168 }
00169 }