From 1acada592d7c23c090c7d1b62ecafab1aabf813b Mon Sep 17 00:00:00 2001 From: Peter O Date: Thu, 16 Jul 2020 11:32:47 -0400 Subject: [PATCH] edit tests --- CBORTest/CBORObjectTest.cs | 12 ++++++------ CBORTest/CBORTest.cs | 16 ++++++++++++---- CBORTest/RandomObjects.cs | 4 ++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CBORTest/CBORObjectTest.cs b/CBORTest/CBORObjectTest.cs index 217f40cf..9aa29b5b 100644 --- a/CBORTest/CBORObjectTest.cs +++ b/CBORTest/CBORObjectTest.cs @@ -7303,7 +7303,7 @@ public static void AssertJSONInteger( } [Test] - [Timeout(2000)] + [Timeout(10000)] public void TestFromJsonStringLongSpecific1() { JSONOptions jsonop = JSONOptions.Default; string json = "{\"x\":-9.2574033594381E-7962\u002c\"1\":" + @@ -7432,7 +7432,7 @@ public void TestFromJsonStringLongKindFull2() { } [Test] - [Timeout(2000)] + [Timeout(10000)] public void TestFromJsonStringLongKindFullBad() { Console.WriteLine("FullBad 1"); var jsonop = new JSONOptions("numberconversion=full"); @@ -7470,7 +7470,7 @@ public void TestFromJsonStringLongKindFullBad() { } [Test] - [Timeout(2000)] + [Timeout(10000)] public void TestFromJsonStringLongKindsBad() { JSONOptions jsonop; string json = TestCommon.Repeat("7", 1000000) + "x"; @@ -7538,7 +7538,7 @@ public void TestFromJsonStringLongKindsBad() { } [Test] - [Timeout(2000)] + [Timeout(10000)] public void TestFromJsonStringLongKindIntOrFloatFromDouble() { var jsonop = new JSONOptions("numberconversion=intorfloatfromdouble"); string manysevens = TestCommon.Repeat("7", 1000000); @@ -7557,7 +7557,7 @@ public void TestFromJsonStringLongKindIntOrFloatFromDouble() { } [Test] - [Timeout(2000)] + [Timeout(10000)] public void TestFromJsonStringLongKindIntOrFloat() { var jsonop = new JSONOptions("numberconversion=intorfloat"); string json = TestCommon.Repeat("7", 1000000); @@ -7567,7 +7567,7 @@ public void TestFromJsonStringLongKindIntOrFloat() { } [Test] - [Timeout(2000)] + [Timeout(10000)] public void TestFromJsonStringLongKindIntOrFloat2() { var jsonop = new JSONOptions("numberconversion=intorfloat"); string json = "-" + TestCommon.Repeat("7", 1000000); diff --git a/CBORTest/CBORTest.cs b/CBORTest/CBORTest.cs index c7f74196..77971be0 100644 --- a/CBORTest/CBORTest.cs +++ b/CBORTest/CBORTest.cs @@ -2725,6 +2725,12 @@ public void TestAsNumberAddSubtract() { public static bool TestAsNumberMultiplyDivideOne( CBORObject o1, CBORObject o2) { + if (o1 == null) { + throw new ArgumentNullException(nameof(o1)); + } + if (o2 == null) { + throw new ArgumentNullException(nameof(o2)); + } if (!o1.IsNumber || !o2.IsNumber) { return false; } @@ -2761,7 +2767,9 @@ public static bool TestAsNumberMultiplyDivideOne( "o1=" + TestCommon.ToByteArrayString(eb1) + "\n" + "o2=" + TestCommon.ToByteArrayString(eb2) + "\n"); } - VerifyEqual(on2a, on2, o1, o2); + if (!on1.IsZero() && !on2.IsZero()) { + VerifyEqual(on2a, on2, o1, o2); + } CBORNumber on1a = onSum.Divide(on2); // NOTE: Ignore if divisor is zero if (!on2.IsZero() && !on1a.IsFinite()) { @@ -2773,7 +2781,7 @@ public static bool TestAsNumberMultiplyDivideOne( "ecodeFromBytes(bytes1),\n" + "CBORObject.DecodeFromBytes(bytes2));\n}\n"); } - if (!o1.IsZero() && !o2.IsZero()) { + if (!on1.IsZero() && !on2.IsZero()) { VerifyEqual(on1a, on1, o1, o2); } return true; @@ -2783,8 +2791,8 @@ public static bool TestAsNumberMultiplyDivideOne( [Timeout(100000)] public void TestAsNumberMultiplyDivide() { var bo1 = new byte[] { - 0x1b, 0x75, (byte)0xdd, (byte)0xb0, (byte)0xcc, - 0x50, (byte)0x9b, (byte)0xd0, 0x2b, + 0x1b, 0x75, (byte)0xdd, (byte)0xb0, + (byte)0xcc, 0x50, (byte)0x9b, (byte)0xd0, 0x2b, }; var bo2 = new byte[] { (byte)0xc5, (byte)0x82, 0x23, 0x00 }; CBORObject cbor1 = CBORObject.DecodeFromBytes(bo1); diff --git a/CBORTest/RandomObjects.cs b/CBORTest/RandomObjects.cs index c4f9424b..877c2ffe 100644 --- a/CBORTest/RandomObjects.cs +++ b/CBORTest/RandomObjects.cs @@ -400,8 +400,8 @@ public static EFloat CloseToPowerOfTwo(IRandomGenExtended rg) { if (rg.GetInt32(10) == 0) { pwr2 = pwr - (rg.GetInt32(100) < 80 ? IntInRange(rg, 51, 61) : IntInRange(rg, 2, 300)); - ef = (rg.GetInt32(2) == 0) ? (ef.Add(EFloat.Create(1, pwr2))) : -(ef.Subtract(EFloat.Create(1, pwr2))); + ef = (rg.GetInt32(2) == 0) ? ef.Add(EFloat.Create(1, pwr2)) : +ef.Subtract(EFloat.Create(1, pwr2)); } return ef; }