public void OTFixedToDoubleTest() { OTFixed target = new OTFixed(new byte[4] { 0, 1, 0x80, 0 }); double expected = 1.5; double actual = target.ToDouble(); Assert.AreEqual(expected, actual, "Error: unexpected value"); }
public void OTFixedMantissaTest2() { OTFixed target = new OTFixed(0xF0008000); short expected = -4096; short actual = target.Mantissa; Assert.AreEqual(expected, actual, "Error: unexpected value"); }
public void OTFixedMantissaTest1() { OTFixed target = new OTFixed(-5, 0); short expected = -5; short actual = target.Mantissa; Assert.AreEqual(expected, actual, "Error: unexpected value"); }
public void OTFixedConstructorTest1() { short mantissa = 0x0001; ushort fraction = 0x5000; OTFixed target = new OTFixed(mantissa, fraction); Assert.IsTrue((mantissa == target.Mantissa) && (fraction == target.Fraction), "Error: unexpected values"); }
public void OTFixedFractionTest() { OTFixed target = new OTFixed(0, 0x5000); ushort expected = 0x5000; ushort actual = target.Fraction; Assert.AreEqual(expected, actual, "Error: unexpected value"); }
public void OTFixedGetFixedAsUInt32Test() { OTFixed target = new OTFixed(1, 0x5000); uint expected = 0x00015000; uint actual; actual = target.GetFixedAsUInt32(); Assert.AreEqual(expected, actual, "Error: unexpected value"); }
public void OTFixedToStringTest() { OTFixed target = new OTFixed(new byte[4] { 0, 1, 0x80, 0 }); string expected = "1.5"; string actual; actual = target.ToString(); Assert.AreEqual(expected, actual, "Error: unexpected value"); }
public void OTFixedOpConvExplicitTest() { byte[] fixedBuffer = new byte[4] { 0, 1, 0x50, 0 }; OTFixed expected = new OTFixed(1, 0x5000); OTFixed actual; actual = ((OTFixed)(fixedBuffer)); Assert.AreEqual(expected, actual, "Error: unexpected conversion result"); }
public void OTFixedGetHashCodeTest() { OTFixed target = new OTFixed(new byte[4] { 0, 1, 0x80, 0 }); int expected = 0x00018000; int actual; actual = target.GetHashCode(); Assert.AreEqual(expected, actual, "Error: unexpected value"); }
public void OTFixedGetBytesTest() { OTFixed target = new OTFixed(1, 0x5000); byte[] expected = new byte[4] { 0, 1, 0x50, 0 }; byte[] actual = target.GetBytes(); bool result = true; for (int i = 0; i < 4; i++) { if (expected[i] != actual[i]) { result = false; break; } } Assert.IsTrue(result, "Error: unexpected value"); }
public void OTFixedReadFixedTest2() { byte[] b = new byte[5] { 0, 1, 0x50, 0, 1 }; MemoryStream ms = new MemoryStream(b); OTFixed expected = new OTFixed(1, 0x5000); OTFixed actual = new OTFixed(); try { actual = OTFixed.ReadFixed(ms); } catch (Exception) { // unexpected exception } Assert.IsTrue(expected == actual, "Error: unexpected value read"); }
public void OTFixedOpConvImplicitTest3() { OTFixed fixedStruct = new OTFixed(1, 0x5000); byte[] expected = new byte[4] { 0, 1, 0x50, 0 }; byte[] actual; actual = fixedStruct; bool result = true; for (int i = 0; i < 4; i++) { if (expected[i] != actual[i]) { result = false; break; } } Assert.IsTrue(result, "Error: unexpected conversion result"); }
public void OTFixedReadFixedTest1() { bool caughtExpectedException = false; // will set to true if expected exception is caught byte[] b = new byte[1] { 0 }; MemoryStream ms = new MemoryStream(b); try { OTFixed f = OTFixed.ReadFixed(ms); } catch (OTDataIncompleteReadException) { caughtExpectedException = true; // caught expected argument: test passes } catch (Exception) { // unexpected exception } Assert.IsTrue(caughtExpectedException, "Error: expected exception not caught"); b = new byte[3] { 0, 1, 0 }; ms = new MemoryStream(b); try { OTFixed f = OTFixed.ReadFixed(ms); } catch (OTDataTypeReadException) { caughtExpectedException = true; // caught expected argument: test passes } catch (Exception) { // unexpected exception } Assert.IsTrue(caughtExpectedException, "Error: expected exception not caught"); }
public void OTFixedEqualsTest1a() { OTFixed target = new OTFixed(new byte[4] { 0, 1, 0x80, 0 }); object obj = new OTFixed(1, 0x8000); Assert.IsTrue(target.Equals(obj), "Error: unexpected comparison result"); }
public void OTFixedEqualsTest2c() { OTFixed target = new OTFixed(new byte[4] { 0, 1, 0x80, 0 }); OTFixed fixedVal = new OTFixed(2, 0x8000); Assert.IsFalse(target.Equals(fixedVal), "Error: unexpected comparison result"); }
public void OTFixedEqualsTest3e() { OTFixed target = new OTFixed(new byte[4] { 0, 1, 0x80, 0 }); byte[] buffer = null; Assert.IsFalse(target.Equals(buffer), "Error: unexpected comparison result"); }
public void OTFixedOperator_InequalityTest1a() { OTFixed lhs = new OTFixed(new byte[4] { 0, 1, 0x80, 0 }); OTFixed rhs = new OTFixed(1, 0x7f00); Assert.IsTrue(lhs != rhs, "Error: unexpected operator result"); }
public void OTFixedOperator_InequalityTest2a() { OTFixed lhs = new OTFixed(1, 0x5000); byte[] rhs = new byte[4] { 0, 1, 0x4f, 0 }; Assert.IsTrue(lhs != rhs, "Error: unexpected operator result"); }
public void OTFixedOperator_InequalityTest3b() { byte[] lhs = new byte[4] { 0, 1, 0x50, 0 }; OTFixed rhs = new OTFixed(1, 0x5000); Assert.IsFalse(lhs != rhs, "Error: unexpected operator result"); }
public void OTFixedConstructorTest2() { byte[] buffer = new byte[4] { 0, 1, 0x50, 0 }; OTFixed target = new OTFixed(buffer); Assert.IsTrue((target.Mantissa == 1) && (target.Fraction == 0x5000), "Error: unexpected values"); }
public void OTFixedEqualsTest1c() { OTFixed target = new OTFixed(new byte[4] { 0, 1, 0x7f, 0 }); object obj = null; Assert.IsFalse(target.Equals(obj), "Error: unexpected comparison result"); }