Ejemplo n.º 1
0
        public static void TestGetHashCode()
        {
            var jsonNumber = new JsonNumber(123);

            Assert.Equal(jsonNumber.GetHashCode(), new JsonNumber(123).GetHashCode());
            Assert.Equal(jsonNumber.GetHashCode(), new JsonNumber((ushort)123).GetHashCode());
            Assert.Equal(jsonNumber.GetHashCode(), new JsonNumber("123").GetHashCode());
            Assert.NotEqual(jsonNumber.GetHashCode(), new JsonNumber("123e0").GetHashCode());
            Assert.NotEqual(jsonNumber.GetHashCode(), new JsonNumber("123e1").GetHashCode());
            Assert.NotEqual(jsonNumber.GetHashCode(), new JsonNumber(17).GetHashCode());

            JsonNode jsonNode = new JsonNumber(123);

            Assert.Equal(jsonNumber.GetHashCode(), jsonNode.GetHashCode());

            IEquatable <JsonNumber> jsonNumberIEquatable = jsonNumber;

            Assert.Equal(jsonNumber.GetHashCode(), jsonNumberIEquatable.GetHashCode());

            object jsonNumberCopy   = jsonNumber;
            object jsonNumberObject = new JsonNumber(17);

            Assert.Equal(jsonNumber.GetHashCode(), jsonNumberCopy.GetHashCode());
            Assert.NotEqual(jsonNumber.GetHashCode(), jsonNumberObject.GetHashCode());

            Assert.Equal(new JsonNumber().GetHashCode(), new JsonNumber().GetHashCode());
        }
Ejemplo n.º 2
0
        public void TestNumberEquality()
        {
            var numberOne1 = new JsonNumber(1, "1");
            var numberOne2 = new JsonNumber(1, "1.0");
            var numberTwo  = new JsonNumber(2, "2");

            Assert.Equal(numberOne1, numberOne2);
            Assert.NotEqual(numberOne1, numberTwo);

            Assert.Equal(numberOne1.GetHashCode(), numberOne2.GetHashCode());
            Assert.NotEqual(numberOne1.GetHashCode(), numberTwo.GetHashCode());
        }
Ejemplo n.º 3
0
        public static void JsonNumberMethodsTest()
        {
            JsonNumber intA = 233, intB = 666, intC = 666, floatA = 43.25, floatB = 96.625, floatC = 96.625;
            object     objA = "";

            Assert.True(floatA.IsFloat);
            Assert.True(floatB.IsFloat);
            Assert.False(intA.IsFloat);
            Assert.False(intB.IsFloat);

            Assert.True(intB == intC);
            Assert.False(intB != intC);

            Assert.Equal <double>(233, intA);
            Assert.Equal <double>(43.25, floatA);

            Assert.True(intB.Equals(intC));
            Assert.False(intA.Equals(intB));
            Assert.False(intA.Equals(floatA));
            Assert.True(floatB.Equals(floatC));

            Assert.True(intB.Equals((object)intB));
            Assert.True(intB.Equals((object)intC));
            Assert.False(intB.Equals(objA));
            Assert.False(intB.Equals((object)null));
            Assert.False(intB.Equals(null));

            Assert.Equal(intB.ValueInt.GetHashCode(), intB.GetHashCode());
            Assert.Equal(floatB.ValueFloat.GetHashCode(), floatB.GetHashCode());
            Assert.Throws <ArgumentOutOfRangeException>(() => new JsonNumber("invalid"));
        }