LSL_TypesTestLSLFloat.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System.Collections.Generic;
  28. using NUnit.Framework;
  29. using OpenSim.Tests.Common;
  30. using OpenSim.Region.ScriptEngine.Shared;
  31. namespace OpenSim.Region.ScriptEngine.Shared.Tests
  32. {
  33. [TestFixture]
  34. public class LSL_TypesTestLSLFloat : OpenSimTestCase
  35. {
  36. // Used for testing equality of two floats.
  37. private double _lowPrecisionTolerance = 0.000001;
  38. private Dictionary<int, double> m_intDoubleSet;
  39. private Dictionary<double, double> m_doubleDoubleSet;
  40. private Dictionary<double, int> m_doubleIntSet;
  41. private Dictionary<double, int> m_doubleUintSet;
  42. private Dictionary<string, double> m_stringDoubleSet;
  43. private Dictionary<double, string> m_doubleStringSet;
  44. private List<int> m_intList;
  45. private List<double> m_doubleList;
  46. /// <summary>
  47. /// Sets up dictionaries and arrays used in the tests.
  48. /// </summary>
  49. [TestFixtureSetUp]
  50. public void SetUpDataSets()
  51. {
  52. m_intDoubleSet = new Dictionary<int, double>();
  53. m_intDoubleSet.Add(2, 2.0);
  54. m_intDoubleSet.Add(-2, -2.0);
  55. m_intDoubleSet.Add(0, 0.0);
  56. m_intDoubleSet.Add(1, 1.0);
  57. m_intDoubleSet.Add(-1, -1.0);
  58. m_intDoubleSet.Add(999999999, 999999999.0);
  59. m_intDoubleSet.Add(-99999999, -99999999.0);
  60. m_doubleDoubleSet = new Dictionary<double, double>();
  61. m_doubleDoubleSet.Add(2.0, 2.0);
  62. m_doubleDoubleSet.Add(-2.0, -2.0);
  63. m_doubleDoubleSet.Add(0.0, 0.0);
  64. m_doubleDoubleSet.Add(1.0, 1.0);
  65. m_doubleDoubleSet.Add(-1.0, -1.0);
  66. m_doubleDoubleSet.Add(999999999.0, 999999999.0);
  67. m_doubleDoubleSet.Add(-99999999.0, -99999999.0);
  68. m_doubleDoubleSet.Add(0.5, 0.5);
  69. m_doubleDoubleSet.Add(0.0005, 0.0005);
  70. m_doubleDoubleSet.Add(0.6805, 0.6805);
  71. m_doubleDoubleSet.Add(-0.5, -0.5);
  72. m_doubleDoubleSet.Add(-0.0005, -0.0005);
  73. m_doubleDoubleSet.Add(-0.6805, -0.6805);
  74. m_doubleDoubleSet.Add(548.5, 548.5);
  75. m_doubleDoubleSet.Add(2.0005, 2.0005);
  76. m_doubleDoubleSet.Add(349485435.6805, 349485435.6805);
  77. m_doubleDoubleSet.Add(-548.5, -548.5);
  78. m_doubleDoubleSet.Add(-2.0005, -2.0005);
  79. m_doubleDoubleSet.Add(-349485435.6805, -349485435.6805);
  80. m_doubleIntSet = new Dictionary<double, int>();
  81. m_doubleIntSet.Add(2.0, 2);
  82. m_doubleIntSet.Add(-2.0, -2);
  83. m_doubleIntSet.Add(0.0, 0);
  84. m_doubleIntSet.Add(1.0, 1);
  85. m_doubleIntSet.Add(-1.0, -1);
  86. m_doubleIntSet.Add(999999999.0, 999999999);
  87. m_doubleIntSet.Add(-99999999.0, -99999999);
  88. m_doubleIntSet.Add(0.5, 0);
  89. m_doubleIntSet.Add(0.0005, 0);
  90. m_doubleIntSet.Add(0.6805, 0);
  91. m_doubleIntSet.Add(-0.5, 0);
  92. m_doubleIntSet.Add(-0.0005, 0);
  93. m_doubleIntSet.Add(-0.6805, 0);
  94. m_doubleIntSet.Add(548.5, 548);
  95. m_doubleIntSet.Add(2.0005, 2);
  96. m_doubleIntSet.Add(349485435.6805, 349485435);
  97. m_doubleIntSet.Add(-548.5, -548);
  98. m_doubleIntSet.Add(-2.0005, -2);
  99. m_doubleIntSet.Add(-349485435.6805, -349485435);
  100. m_doubleUintSet = new Dictionary<double, int>();
  101. m_doubleUintSet.Add(2.0, 2);
  102. m_doubleUintSet.Add(-2.0, 2);
  103. m_doubleUintSet.Add(0.0, 0);
  104. m_doubleUintSet.Add(1.0, 1);
  105. m_doubleUintSet.Add(-1.0, 1);
  106. m_doubleUintSet.Add(999999999.0, 999999999);
  107. m_doubleUintSet.Add(-99999999.0, 99999999);
  108. m_doubleUintSet.Add(0.5, 0);
  109. m_doubleUintSet.Add(0.0005, 0);
  110. m_doubleUintSet.Add(0.6805, 0);
  111. m_doubleUintSet.Add(-0.5, 0);
  112. m_doubleUintSet.Add(-0.0005, 0);
  113. m_doubleUintSet.Add(-0.6805, 0);
  114. m_doubleUintSet.Add(548.5, 548);
  115. m_doubleUintSet.Add(2.0005, 2);
  116. m_doubleUintSet.Add(349485435.6805, 349485435);
  117. m_doubleUintSet.Add(-548.5, 548);
  118. m_doubleUintSet.Add(-2.0005, 2);
  119. m_doubleUintSet.Add(-349485435.6805, 349485435);
  120. m_stringDoubleSet = new Dictionary<string, double>();
  121. m_stringDoubleSet.Add("2", 2.0);
  122. m_stringDoubleSet.Add("-2", -2.0);
  123. m_stringDoubleSet.Add("1", 1.0);
  124. m_stringDoubleSet.Add("-1", -1.0);
  125. m_stringDoubleSet.Add("0", 0.0);
  126. m_stringDoubleSet.Add("999999999.0", 999999999.0);
  127. m_stringDoubleSet.Add("-99999999.0", -99999999.0);
  128. m_stringDoubleSet.Add("0.5", 0.5);
  129. m_stringDoubleSet.Add("0.0005", 0.0005);
  130. m_stringDoubleSet.Add("0.6805", 0.6805);
  131. m_stringDoubleSet.Add("-0.5", -0.5);
  132. m_stringDoubleSet.Add("-0.0005", -0.0005);
  133. m_stringDoubleSet.Add("-0.6805", -0.6805);
  134. m_stringDoubleSet.Add("548.5", 548.5);
  135. m_stringDoubleSet.Add("2.0005", 2.0005);
  136. m_stringDoubleSet.Add("349485435.6805", 349485435.6805);
  137. m_stringDoubleSet.Add("-548.5", -548.5);
  138. m_stringDoubleSet.Add("-2.0005", -2.0005);
  139. m_stringDoubleSet.Add("-349485435.6805", -349485435.6805);
  140. // some oddball combinations and exponents
  141. m_stringDoubleSet.Add("", 0.0);
  142. m_stringDoubleSet.Add("1.0E+5", 100000.0);
  143. m_stringDoubleSet.Add("-1.0E+5", -100000.0);
  144. m_stringDoubleSet.Add("-1E+5", -100000.0);
  145. m_stringDoubleSet.Add("-1.E+5", -100000.0);
  146. m_stringDoubleSet.Add("-1.E+5.0", -100000.0);
  147. m_stringDoubleSet.Add("1ef", 1.0);
  148. m_stringDoubleSet.Add("e10", 0.0);
  149. m_stringDoubleSet.Add("1.e0.0", 1.0);
  150. m_doubleStringSet = new Dictionary<double, string>();
  151. m_doubleStringSet.Add(2.0, "2.000000");
  152. m_doubleStringSet.Add(-2.0, "-2.000000");
  153. m_doubleStringSet.Add(1.0, "1.000000");
  154. m_doubleStringSet.Add(-1.0, "-1.000000");
  155. m_doubleStringSet.Add(0.0, "0.000000");
  156. m_doubleStringSet.Add(999999999.0, "999999999.000000");
  157. m_doubleStringSet.Add(-99999999.0, "-99999999.000000");
  158. m_doubleStringSet.Add(0.5, "0.500000");
  159. m_doubleStringSet.Add(0.0005, "0.000500");
  160. m_doubleStringSet.Add(0.6805, "0.680500");
  161. m_doubleStringSet.Add(-0.5, "-0.500000");
  162. m_doubleStringSet.Add(-0.0005, "-0.000500");
  163. m_doubleStringSet.Add(-0.6805, "-0.680500");
  164. m_doubleStringSet.Add(548.5, "548.500000");
  165. m_doubleStringSet.Add(2.0005, "2.000500");
  166. m_doubleStringSet.Add(349485435.6805, "349485435.680500");
  167. m_doubleStringSet.Add(-548.5, "-548.500000");
  168. m_doubleStringSet.Add(-2.0005, "-2.000500");
  169. m_doubleStringSet.Add(-349485435.6805, "-349485435.680500");
  170. m_doubleList = new List<double>();
  171. m_doubleList.Add(2.0);
  172. m_doubleList.Add(-2.0);
  173. m_doubleList.Add(1.0);
  174. m_doubleList.Add(-1.0);
  175. m_doubleList.Add(999999999.0);
  176. m_doubleList.Add(-99999999.0);
  177. m_doubleList.Add(0.5);
  178. m_doubleList.Add(0.0005);
  179. m_doubleList.Add(0.6805);
  180. m_doubleList.Add(-0.5);
  181. m_doubleList.Add(-0.0005);
  182. m_doubleList.Add(-0.6805);
  183. m_doubleList.Add(548.5);
  184. m_doubleList.Add(2.0005);
  185. m_doubleList.Add(349485435.6805);
  186. m_doubleList.Add(-548.5);
  187. m_doubleList.Add(-2.0005);
  188. m_doubleList.Add(-349485435.6805);
  189. m_intList = new List<int>();
  190. m_intList.Add(2);
  191. m_intList.Add(-2);
  192. m_intList.Add(0);
  193. m_intList.Add(1);
  194. m_intList.Add(-1);
  195. m_intList.Add(999999999);
  196. m_intList.Add(-99999999);
  197. }
  198. /// <summary>
  199. /// Tests constructing a LSLFloat from an integer.
  200. /// </summary>
  201. [Test]
  202. public void TestConstructFromInt()
  203. {
  204. TestHelpers.InMethod();
  205. LSL_Types.LSLFloat testFloat;
  206. foreach (KeyValuePair<int, double> number in m_intDoubleSet)
  207. {
  208. testFloat = new LSL_Types.LSLFloat(number.Key);
  209. Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
  210. }
  211. }
  212. /// <summary>
  213. /// Tests constructing a LSLFloat from a double.
  214. /// </summary>
  215. [Test]
  216. public void TestConstructFromDouble()
  217. {
  218. TestHelpers.InMethod();
  219. LSL_Types.LSLFloat testFloat;
  220. foreach (KeyValuePair<double, double> number in m_doubleDoubleSet)
  221. {
  222. testFloat = new LSL_Types.LSLFloat(number.Key);
  223. Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
  224. }
  225. }
  226. /// <summary>
  227. /// Tests LSLFloat is correctly cast explicitly to integer.
  228. /// </summary>
  229. [Test]
  230. public void TestExplicitCastLSLFloatToInt()
  231. {
  232. TestHelpers.InMethod();
  233. int testNumber;
  234. foreach (KeyValuePair<double, int> number in m_doubleIntSet)
  235. {
  236. testNumber = (int) new LSL_Types.LSLFloat(number.Key);
  237. Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting int " + number.Value);
  238. }
  239. }
  240. /// <summary>
  241. /// Tests LSLFloat is correctly cast explicitly to unsigned integer.
  242. /// </summary>
  243. [Test]
  244. public void TestExplicitCastLSLFloatToUint()
  245. {
  246. TestHelpers.InMethod();
  247. uint testNumber;
  248. foreach (KeyValuePair<double, int> number in m_doubleUintSet)
  249. {
  250. testNumber = (uint) new LSL_Types.LSLFloat(number.Key);
  251. Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting uint " + number.Value);
  252. }
  253. }
  254. /// <summary>
  255. /// Tests LSLFloat is correctly cast implicitly to Boolean if non-zero.
  256. /// </summary>
  257. [Test]
  258. public void TestImplicitCastLSLFloatToBooleanTrue()
  259. {
  260. TestHelpers.InMethod();
  261. LSL_Types.LSLFloat testFloat;
  262. bool testBool;
  263. foreach (double number in m_doubleList)
  264. {
  265. testFloat = new LSL_Types.LSLFloat(number);
  266. testBool = testFloat;
  267. Assert.IsTrue(testBool);
  268. }
  269. }
  270. /// <summary>
  271. /// Tests LSLFloat is correctly cast implicitly to Boolean if zero.
  272. /// </summary>
  273. [Test]
  274. public void TestImplicitCastLSLFloatToBooleanFalse()
  275. {
  276. TestHelpers.InMethod();
  277. LSL_Types.LSLFloat testFloat = new LSL_Types.LSLFloat(0.0);
  278. bool testBool = testFloat;
  279. Assert.IsFalse(testBool);
  280. }
  281. /// <summary>
  282. /// Tests integer is correctly cast implicitly to LSLFloat.
  283. /// </summary>
  284. [Test]
  285. public void TestImplicitCastIntToLSLFloat()
  286. {
  287. TestHelpers.InMethod();
  288. LSL_Types.LSLFloat testFloat;
  289. foreach (int number in m_intList)
  290. {
  291. testFloat = number;
  292. Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
  293. }
  294. }
  295. /// <summary>
  296. /// Tests LSLInteger is correctly cast implicitly to LSLFloat.
  297. /// </summary>
  298. [Test]
  299. public void TestImplicitCastLSLIntegerToLSLFloat()
  300. {
  301. TestHelpers.InMethod();
  302. LSL_Types.LSLFloat testFloat;
  303. foreach (int number in m_intList)
  304. {
  305. testFloat = new LSL_Types.LSLInteger(number);
  306. Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
  307. }
  308. }
  309. /// <summary>
  310. /// Tests LSLInteger is correctly cast explicitly to LSLFloat.
  311. /// </summary>
  312. [Test]
  313. public void TestExplicitCastLSLIntegerToLSLFloat()
  314. {
  315. TestHelpers.InMethod();
  316. LSL_Types.LSLFloat testFloat;
  317. foreach (int number in m_intList)
  318. {
  319. testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLInteger(number);
  320. Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
  321. }
  322. }
  323. /// <summary>
  324. /// Tests string is correctly cast explicitly to LSLFloat.
  325. /// </summary>
  326. [Test]
  327. public void TestExplicitCastStringToLSLFloat()
  328. {
  329. TestHelpers.InMethod();
  330. LSL_Types.LSLFloat testFloat;
  331. foreach (KeyValuePair<string, double> number in m_stringDoubleSet)
  332. {
  333. testFloat = (LSL_Types.LSLFloat) number.Key;
  334. Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
  335. }
  336. }
  337. /// <summary>
  338. /// Tests LSLString is correctly cast implicitly to LSLFloat.
  339. /// </summary>
  340. [Test]
  341. public void TestExplicitCastLSLStringToLSLFloat()
  342. {
  343. TestHelpers.InMethod();
  344. LSL_Types.LSLFloat testFloat;
  345. foreach (KeyValuePair<string, double> number in m_stringDoubleSet)
  346. {
  347. testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLString(number.Key);
  348. Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance));
  349. }
  350. }
  351. /// <summary>
  352. /// Tests double is correctly cast implicitly to LSLFloat.
  353. /// </summary>
  354. [Test]
  355. public void TestImplicitCastDoubleToLSLFloat()
  356. {
  357. TestHelpers.InMethod();
  358. LSL_Types.LSLFloat testFloat;
  359. foreach (double number in m_doubleList)
  360. {
  361. testFloat = number;
  362. Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
  363. }
  364. }
  365. /// <summary>
  366. /// Tests LSLFloat is correctly cast implicitly to double.
  367. /// </summary>
  368. [Test]
  369. public void TestImplicitCastLSLFloatToDouble()
  370. {
  371. TestHelpers.InMethod();
  372. double testNumber;
  373. LSL_Types.LSLFloat testFloat;
  374. foreach (double number in m_doubleList)
  375. {
  376. testFloat = new LSL_Types.LSLFloat(number);
  377. testNumber = testFloat;
  378. Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
  379. }
  380. }
  381. /// <summary>
  382. /// Tests LSLFloat is correctly cast explicitly to float
  383. /// </summary>
  384. [Test]
  385. public void TestExplicitCastLSLFloatToFloat()
  386. {
  387. TestHelpers.InMethod();
  388. float testFloat;
  389. float numberAsFloat;
  390. LSL_Types.LSLFloat testLSLFloat;
  391. foreach (double number in m_doubleList)
  392. {
  393. testLSLFloat = new LSL_Types.LSLFloat(number);
  394. numberAsFloat = (float)number;
  395. testFloat = (float)testLSLFloat;
  396. Assert.That((double)testFloat, new DoubleToleranceConstraint((double)numberAsFloat, _lowPrecisionTolerance));
  397. }
  398. }
  399. /// <summary>
  400. /// Tests the equality (==) operator.
  401. /// </summary>
  402. [Test]
  403. public void TestEqualsOperator()
  404. {
  405. TestHelpers.InMethod();
  406. LSL_Types.LSLFloat testFloatA, testFloatB;
  407. foreach (double number in m_doubleList)
  408. {
  409. testFloatA = new LSL_Types.LSLFloat(number);
  410. testFloatB = new LSL_Types.LSLFloat(number);
  411. Assert.IsTrue(testFloatA == testFloatB);
  412. testFloatB = new LSL_Types.LSLFloat(number + 1.0);
  413. Assert.IsFalse(testFloatA == testFloatB);
  414. }
  415. }
  416. /// <summary>
  417. /// Tests the inequality (!=) operator.
  418. /// </summary>
  419. [Test]
  420. public void TestNotEqualOperator()
  421. {
  422. TestHelpers.InMethod();
  423. LSL_Types.LSLFloat testFloatA, testFloatB;
  424. foreach (double number in m_doubleList)
  425. {
  426. testFloatA = new LSL_Types.LSLFloat(number);
  427. testFloatB = new LSL_Types.LSLFloat(number + 1.0);
  428. Assert.IsTrue(testFloatA != testFloatB);
  429. testFloatB = new LSL_Types.LSLFloat(number);
  430. Assert.IsFalse(testFloatA != testFloatB);
  431. }
  432. }
  433. /// <summary>
  434. /// Tests the increment operator.
  435. /// </summary>
  436. [Test]
  437. public void TestIncrementOperator()
  438. {
  439. TestHelpers.InMethod();
  440. LSL_Types.LSLFloat testFloat;
  441. double testNumber;
  442. foreach (double number in m_doubleList)
  443. {
  444. testFloat = new LSL_Types.LSLFloat(number);
  445. testNumber = testFloat++;
  446. Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
  447. testNumber = testFloat;
  448. Assert.That(testNumber, new DoubleToleranceConstraint(number + 1.0, _lowPrecisionTolerance));
  449. testNumber = ++testFloat;
  450. Assert.That(testNumber, new DoubleToleranceConstraint(number + 2.0, _lowPrecisionTolerance));
  451. }
  452. }
  453. /// <summary>
  454. /// Tests the decrement operator.
  455. /// </summary>
  456. [Test]
  457. public void TestDecrementOperator()
  458. {
  459. TestHelpers.InMethod();
  460. LSL_Types.LSLFloat testFloat;
  461. double testNumber;
  462. foreach (double number in m_doubleList)
  463. {
  464. testFloat = new LSL_Types.LSLFloat(number);
  465. testNumber = testFloat--;
  466. Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
  467. testNumber = testFloat;
  468. Assert.That(testNumber, new DoubleToleranceConstraint(number - 1.0, _lowPrecisionTolerance));
  469. testNumber = --testFloat;
  470. Assert.That(testNumber, new DoubleToleranceConstraint(number - 2.0, _lowPrecisionTolerance));
  471. }
  472. }
  473. /// <summary>
  474. /// Tests LSLFloat.ToString().
  475. /// </summary>
  476. [Test]
  477. public void TestToString()
  478. {
  479. TestHelpers.InMethod();
  480. LSL_Types.LSLFloat testFloat;
  481. foreach (KeyValuePair<double, string> number in m_doubleStringSet)
  482. {
  483. testFloat = new LSL_Types.LSLFloat(number.Key);
  484. Assert.AreEqual(number.Value, testFloat.ToString());
  485. }
  486. }
  487. /// <summary>
  488. /// Tests addition of two LSLFloats.
  489. /// </summary>
  490. [Test]
  491. public void TestAddTwoLSLFloats()
  492. {
  493. TestHelpers.InMethod();
  494. LSL_Types.LSLFloat testResult;
  495. foreach (KeyValuePair<double, double> number in m_doubleDoubleSet)
  496. {
  497. testResult = new LSL_Types.LSLFloat(number.Key) + new LSL_Types.LSLFloat(number.Value);
  498. Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key + number.Value, _lowPrecisionTolerance));
  499. }
  500. }
  501. /// <summary>
  502. /// Tests subtraction of two LSLFloats.
  503. /// </summary>
  504. [Test]
  505. public void TestSubtractTwoLSLFloats()
  506. {
  507. TestHelpers.InMethod();
  508. LSL_Types.LSLFloat testResult;
  509. foreach (KeyValuePair<double, double> number in m_doubleDoubleSet)
  510. {
  511. testResult = new LSL_Types.LSLFloat(number.Key) - new LSL_Types.LSLFloat(number.Value);
  512. Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key - number.Value, _lowPrecisionTolerance));
  513. }
  514. }
  515. /// <summary>
  516. /// Tests multiplication of two LSLFloats.
  517. /// </summary>
  518. [Test]
  519. public void TestMultiplyTwoLSLFloats()
  520. {
  521. TestHelpers.InMethod();
  522. LSL_Types.LSLFloat testResult;
  523. foreach (KeyValuePair<double, double> number in m_doubleDoubleSet)
  524. {
  525. testResult = new LSL_Types.LSLFloat(number.Key) * new LSL_Types.LSLFloat(number.Value);
  526. Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key * number.Value, _lowPrecisionTolerance));
  527. }
  528. }
  529. /// <summary>
  530. /// Tests division of two LSLFloats.
  531. /// </summary>
  532. [Test]
  533. public void TestDivideTwoLSLFloats()
  534. {
  535. TestHelpers.InMethod();
  536. LSL_Types.LSLFloat testResult;
  537. foreach (KeyValuePair<double, double> number in m_doubleDoubleSet)
  538. {
  539. if (number.Value != 0.0) // Let's avoid divide by zero.
  540. {
  541. testResult = new LSL_Types.LSLFloat(number.Key) / new LSL_Types.LSLFloat(number.Value);
  542. Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key / number.Value, _lowPrecisionTolerance));
  543. }
  544. }
  545. }
  546. /// <summary>
  547. /// Tests boolean correctly cast implicitly to LSLFloat.
  548. /// </summary>
  549. [Test]
  550. public void TestImplicitCastBooleanToLSLFloat()
  551. {
  552. TestHelpers.InMethod();
  553. LSL_Types.LSLFloat testFloat;
  554. testFloat = (1 == 0);
  555. Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance));
  556. testFloat = (1 == 1);
  557. Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance));
  558. testFloat = false;
  559. Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance));
  560. testFloat = true;
  561. Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance));
  562. }
  563. }
  564. }