public void DateTime_MoreTests() { AssertV2.ThrowExeptionIfAssertionFails(false, () => { var dateTime1 = DateTimeV2.NewDateTimeFromUnixTimestamp(1547535889); var dateTime2 = DateTimeV2.NewDateTimeFromUnixTimestamp(1547535889000); Assert.Equal(dateTime1, dateTime2); var dateTime3 = DateTimeV2.NewDateTimeFromUnixTimestamp(1547535889, autoCorrectIfPassedInSeconds: false); Assert.NotEqual(dateTime1, dateTime3); }); AssertV2.ThrowExeptionIfAssertionFails(false, () => { if (AssertV2.throwExeptionIfAssertionFails) { return; } // Abort test if the flag is not correct var dateTime1 = DateTimeV2.NewDateTimeFromUnixTimestamp(-2); var dateTime2 = DateTimeV2.NewDateTimeFromUnixTimestamp(2); Assert.True(dateTime1.IsBefore(dateTime2)); Assert.False(dateTime2.IsBefore(dateTime1)); Assert.True(dateTime2.IsAfter(dateTime1)); Assert.False(dateTime1.IsAfter(dateTime2)); Assert.True(DateTimeV2.NewDateTimeFromUnixTimestamp(0).IsBetween(dateTime1, dateTime2)); Assert.False(DateTimeV2.NewDateTimeFromUnixTimestamp(0).IsBetween(dateTime2, dateTime1)); Assert.False(DateTimeV2.NewDateTimeFromUnixTimestamp(3).IsBetween(dateTime1, dateTime2)); }); }
public void DateTime_MoreTests() { AssertV2.ThrowExeptionIfAssertionFails(false, () => { var dateTime1 = DateTimeParser.NewDateTimeFromUnixTimestamp(1547535889); var dateTime2 = DateTimeParser.NewDateTimeFromUnixTimestamp(1547535889000); Assert.Equal(dateTime1, dateTime2); var dateTime3 = DateTimeParser.NewDateTimeFromUnixTimestamp(1547535889, autoCorrectIfPassedInSeconds: false); Assert.NotEqual(dateTime1, dateTime3); }); AssertV2.ThrowExeptionIfAssertionFails(false, () => { var dateTime1 = DateTimeParser.NewDateTimeFromUnixTimestamp(-2); var dateTime2 = DateTimeParser.NewDateTimeFromUnixTimestamp(2); Assert.True(dateTime1.IsBefore(dateTime2)); Assert.False(dateTime2.IsBefore(dateTime1)); Assert.True(dateTime2.IsAfter(dateTime1)); Assert.False(dateTime1.IsAfter(dateTime2)); Assert.True(DateTimeParser.NewDateTimeFromUnixTimestamp(0).IsBetween(dateTime1, dateTime2)); Assert.False(DateTimeParser.NewDateTimeFromUnixTimestamp(0).IsBetween(dateTime2, dateTime1)); Assert.False(DateTimeParser.NewDateTimeFromUnixTimestamp(3).IsBetween(dateTime1, dateTime2)); }); // Make sure the assertions in DateTimeParser.NewDateTimeFromUnixTimestamp work correctly and detect abnormal behavior: Assert.Throws <Exception>(() => { AssertV2.ThrowExeptionIfAssertionFails(() => { DateTimeParser.NewDateTimeFromUnixTimestamp(-1); }); }); }
public void TestPerformance1() { // The EventBus can be accessed via EventBus.instance EventBus eventBus = GetEventBusForTesting(); string eventName = "TestEvent1 - TestPerformance1"; var receivedEventsCounter = 0; //Register a subscriber for the eventName that gets notified when ever an event is send: object subscriber1 = new object(); // can be of any type eventBus.Subscribe(subscriber1, eventName, () => { receivedEventsCounter++; }); var timing = Log.MethodEntered(); var nrOfEventsSendOut = 1000000; for (int i = 0; i < nrOfEventsSendOut; i++) { eventBus.Publish(eventName); } AssertV2.ThrowExeptionIfAssertionFails(() => { timing.AssertUnderXms(5000); }); Assert.Equal(nrOfEventsSendOut, receivedEventsCounter); }
public void TestAssertV2Methods() { AssertV2.ThrowExeptionIfAssertionFails(() => { AssertV2.IsTrue(1 + 1 == 2, "This assertion must not fail"); var s1 = "a"; AssertV2.AreEqual(s1, s1); AssertV2.IsNull(null, "myVarX"); AssertV2.AreEqual(1, 1); AssertV2.AreNotEqual(1, 2); }); var stopWatch = AssertV2.TrackTiming(); var res = 1f; for (float i = 1; i < 500000; i++) { res = i / res + i; } Assert.NotEqual(0, res); stopWatch.Stop(); AssertV2.ThrowExeptionIfAssertionFails(() => { stopWatch.AssertUnderXms(200); }); Assert.True(stopWatch.IsUnderXms(200), "More time was needed than expected!"); AssertV2.AreEqual("abcd", "abce"); AssertV2.AreEqual(new int[4] { 1, 2, 2, 4 }, new int[4] { 1, 2, 3, 4 }); AssertV2.AreEqual(new int[2] { 1, 2 }, new int[2] { 1, 3 }); AssertV2.AreEqual(new int[6] { 1, 2, 3, 4, 5, 6 }, new int[6] { 1, 2, 3, 4, 5, 7 }); AssertV2.AreEqual(new int[2] { 1, 2 }, new int[1] { 1 }); AssertV2.AreEqual(new int[1] { 1 }, new int[2] { 1, 2 }); }
public void TestAssertV2Throws() { AssertV2.ThrowExeptionIfAssertionFails(() => { try { AssertV2.Throws <Exception>(() => { AssertV2.AreEqual(1, 1); // this will not fail.. }); // ..so the AssertV2.Throws should fail Log.e("This line should never be reached since AssertV2.Throws should fail!"); throw new Exception("AssertV2.Throws did not fail correctly!"); } catch (AssertV2.ThrowsException) { // Only catch it if its a ThrowsException // AssertV2.Throws failed correctly and threw an ThrowsException error Log.d("ThrowsException was expected and arrived correctly"); } }); }
public void TestAssertV2Methods() { AssertV2.ThrowExeptionIfAssertionFails(() => { AssertV2.IsTrue(AssertV2.throwExeptionIfAssertionFails, "AssertV2.throwExeptionIfAssertionFails"); AssertV2.IsTrue(1 + 1 == 2, "This assertion must not fail"); AssertV2.Throws <Exception>(() => { AssertV2.IsTrue(1 + 1 == 4, "This assertion has to fail"); Log.e("This line should never be printed since throwExeptionIfAssertionFails is true"); }); var s1 = "a"; AssertV2.AreEqual(s1, s1); AssertV2.IsTrue(AssertV2.throwExeptionIfAssertionFails, "AssertV2.throwExeptionIfAssertionFails"); AssertV2.Throws <Exception>(() => { AssertV2.AreNotEqual(s1, s1, "s1"); }); string myVarX = null; AssertV2.IsNull(null, "myVarX"); myVarX = "Now myVarX is not null anymore"; AssertV2.Throws <Exception>(() => { AssertV2.IsNull(myVarX, "myVarX"); }); AssertV2.AreEqual(1, 1); AssertV2.Throws <Exception>(() => { AssertV2.AreEqual(1, 2); }); AssertV2.AreNotEqual(1, 2); AssertV2.Throws <Exception>(() => { AssertV2.AreNotEqual(1, 1); }); var stopWatch = AssertV2.TrackTiming(); Thread.Sleep(10); stopWatch.Stop(); AssertV2.Throws <Exception>(() => { stopWatch.AssertUnderXms(1); }); // This should always fail stopWatch.AssertUnderXms(50); AssertV2.IsTrue(stopWatch.IsUnderXms(50), "More time was needed than expected!"); }); }