public void Graph_Remove_Rejects_AlreadyRemoved() { var graph = new Graph <int, int>(x => x); graph.AddNode(0); graph.Remove(0); Assert2.Throws <InvalidOperationException>(() => graph.Remove(0)); }
public void Graph_GetShortestPath_Rejects_UnknownNodes() { var graph = new Graph <int, int>(x => x); List <int> path; int cost; Assert2.Throws <InvalidOperationException>(() => graph.GetShortestPath(0, 1, out path, out cost)); }
public void Test_S1Angle_NormalizeCorrectlyCanonicalizesAngles() { Assert2.DoubleEqual(0.0, S1Angle.FromDegrees(360.0).Normalize().GetDegrees()); Assert2.DoubleEqual(-90.0, S1Angle.FromDegrees(-90.0).Normalize().GetDegrees()); Assert2.DoubleEqual(180.0, S1Angle.FromDegrees(-180.0).Normalize().GetDegrees()); Assert2.DoubleEqual(180.0, S1Angle.FromDegrees(180.0).Normalize().GetDegrees()); Assert2.DoubleEqual(180.0, S1Angle.FromDegrees(540.0).Normalize().GetDegrees()); Assert2.DoubleEqual(90.0, S1Angle.FromDegrees(-270.0).Normalize().GetDegrees()); }
public void Test_MinMax<T>([PexAssumeNotNull] T[] array) where T : IComparable<T> { PexAssume.IsNotNullOrEmpty(array); var seq = OrderedSequence.FromEnumerable(array); Array.Sort(array); Assert.Equal(array[0], seq.Min); Assert.Equal(array[array.Length - 1], seq.Max); Assert2.SequenceEqual(array.Skip(1), seq.ExceptMin); Assert2.SequenceEqual(array.Take(array.Length - 1), seq.ExceptMax); }
public void Test_S1ChordAngle_ToFromS1Angle() { Assert.Equal(0, new S1ChordAngle(S1Angle.Zero).Radians()); Assert.Equal(4, new S1ChordAngle(S1Angle.FromRadians(Math.PI)).Length2); Assert.Equal(Math.PI, new S1ChordAngle(S1Angle.FromRadians(Math.PI)).Radians()); Assert.Equal(S1Angle.Infinity, new S1ChordAngle(S1Angle.Infinity).ToAngle()); Assert.True(new S1ChordAngle(S1Angle.FromRadians(-1)).Radians() < 0); Assert2.DoubleEqual(1.0, new S1ChordAngle(S1Angle.FromRadians(1.0)).Radians()); }
public void Test_LoopTestBase_GetCurvature() { Assert.Equal(-S2.M_2_PI, S2.GetCurvature(full_)); Assert.Equal(S2.M_2_PI, S2.GetCurvature(v_loop_)); CheckCurvatureInvariants(v_loop_); // This curvature should be computed exactly. Assert.Equal(0, S2.GetCurvature(north_hemi3_)); CheckCurvatureInvariants(north_hemi3_); Assert2.Near(0, S2.GetCurvature(west_hemi_), 1e-15); CheckCurvatureInvariants(west_hemi_); // We don't have an easy way to estimate the curvature of these loops, but // we can still check that the expected invariants hold. CheckCurvatureInvariants(candy_cane_); CheckCurvatureInvariants(three_leaf_clover_); Assert2.DoubleEqual(S2.M_2_PI, S2.GetCurvature(line_triangle_)); CheckCurvatureInvariants(line_triangle_); Assert2.DoubleEqual(S2.M_2_PI, S2.GetCurvature(skinny_chevron_)); CheckCurvatureInvariants(skinny_chevron_); // Build a narrow spiral loop starting at the north pole. This is designed // to test that the error in GetCurvature is linear in the number of // vertices even when the partial sum of the curvatures gets very large. // The spiral consists of two "arms" defining opposite sides of the loop. // This is a pathological loop that contains many long parallel edges. int kArmPoints = 10000; // Number of vertices in each "arm" double kArmRadius = 0.01; // Radius of spiral. S2PointLoopSpan spiral = new(2 * kArmPoints); spiral[kArmPoints] = new S2Point(0, 0, 1); for (int i = 0; i < kArmPoints; ++i) { double angle = (S2.M_2_PI / 3) * i; double x = Math.Cos(angle); double y = Math.Sin(angle); double r1 = i * kArmRadius / kArmPoints; double r2 = (i + 1.5) * kArmRadius / kArmPoints; spiral[kArmPoints - i - 1] = new S2Point(r1 * x, r1 * y, 1).Normalize(); spiral[kArmPoints + i] = new S2Point(r2 * x, r2 * y, 1).Normalize(); } // Check that GetCurvature() is consistent with GetArea() to within the // error bound of the former. We actually use a tiny fraction of the // worst-case error bound, since the worst case only happens when all the // roundoff errors happen in the same direction and this test is not // designed to achieve that. The error in GetArea() can be ignored for the // purposes of this test since it is generally much smaller. Assert2.Near( S2.M_2_PI - S2.GetArea(spiral), S2.GetCurvature(spiral), 0.01 * S2.GetCurvatureMaxError(spiral)); }
private static void checkDecode( DeltaZigzagEncoding.Decoder d, int[] data, int[] expected) { int[] r = d.decodeArray(data); Assert2.assertArrayEquals(expected, r); Assert2.assertEquals(r[r.Length - 1], d.getContextValue()); }
public void Test_StoreManyElements<T>([PexAssumeNotNull] T[] array) { var vector = Vector<T>.Empty; for (int i = 0; i < array.Length; i++) vector = vector.SetAt(i, array[i]); for (int i = 0; i < array.Length; i++) Assert.Equal(array[i], vector[i]); Assert.Equal(array.Length, vector.Count); Assert2.SequenceEqual(array, vector); } // StoreManyElements()
protected void Object_AllFields_HaveValues_Multiple() { var objs = GetMultipleItems(); foreach (var obj in objs) { Assert2.AllPropertiesAreNotDefault(obj); } }
public void Cbrt() { void Test(double x) => Assert2.AreNearlyEqual(Math.Pow(x, 1.0 / 3), ElementaryFunctions2.Cbrt(x)); Test(1.0); Test(2.0); Test(3.0); Test(127.0); }
public void Sqrt() { void Test(double x) => Assert2.AreNearlyEqual(Math.Sqrt(x), ElementaryFunctions2.Sqrt(x)); Test(1.0); Test(2.0); Test(3.0); Test(127.0); }
public void LastWeekdayOfMonthFilterInvalidState() { var values = Enum.GetValues(typeof(CrontabFieldKind)).Cast <CrontabFieldKind>().Where(x => x != CrontabFieldKind.Day); foreach (var type in values) { Assert2.Throws <CrontabException>(() => new LastWeekdayOfMonthFilter(type), "Ensure LastWeekdayOfMonth can't be instantiated with <{0}>", Enum.GetName(typeof(CrontabFieldKind), type)); } }
public void TestSimpleAddTake() { ThreadPoolQueueController q = new ThreadPoolQueueController(100, 1000); Assert.IsTrue(q.TryAdd(new TestThreadPoolItem(10), null, false, 0, CancellationToken.None)); ThreadPoolWorkItem res = null; Assert.IsTrue(q.TryTake(null, out res, 0, CancellationToken.None, true)); Assert2.AreEqual(10, res); }
public void TestSimpleAddTake() { ThreadPoolGlobalQueue q = new ThreadPoolGlobalQueue(100); Assert.IsTrue(q.TryAdd(new TestThreadPoolItem(10), 0, CancellationToken.None)); ThreadPoolWorkItem res = null; Assert.IsTrue(q.TryTake(out res, 0, CancellationToken.None, true)); Assert2.AreEqual(10, res); }
public void Invalidates_null_or_empty_vector() { Client.Users.GetByIds("stackoverflow", new int[] { 1, 2, 3 }); Assert2.ThrowsArgumentNullException(() => Client.Users.GetByIds("stackoverflow", null), "ids"); Assert2.ThrowsArgumentException(() => Client.Users.GetByIds("stackoverflow", new int[0]), "ids"); Client.Filters.Read(new string[] { "foo", "bar", "baz" }); Assert2.ThrowsArgumentNullException(() => Client.Filters.Read(null), "filters"); Assert2.ThrowsArgumentException(() => Client.Filters.Read(new string[0]), "filters"); }
public void PropertyHelper_RefStructProperties() { // Arrange var obj = new RefStructProperties(); // Act + Assert var helper = Assert2.Single(PropertyHelper.GetPropertyAccessors(obj.GetType().GetTypeInfo())); Assert2.Equal("Prop5", helper.Name); }
public void checkZigzagDecoder() { DeltaZigzagEncoding.Decoder d = new DeltaZigzagEncoding.Decoder(0); Assert2.assertEquals(0, zigzagDecode(d, 0)); Assert2.assertEquals(-1, zigzagDecode(d, 1)); Assert2.assertEquals(1, zigzagDecode(d, 2)); Assert2.assertEquals(-2, zigzagDecode(d, 3)); Assert2.assertEquals(2, zigzagDecode(d, 4)); Assert2.assertEquals(-3, zigzagDecode(d, 5)); }
public void ExecuteVoidValueMethod() { var executor = GetExecutorForMethod(nameof(TestObject.VoidValueMethod)); var result = executor.Execute( _targetObject, new object[] { 10 }); Assert2.False(executor.IsMethodAsync); Assert2.Null(result); }
public void CheckContextualValidationRules() { Func <CourseDelete.Request, ValidationMessageCollection> CallSut = request => { var response = DomainServices.Dispatch(request); return(response.ValidationDetails); }; Assert2.CheckContextualValidation("CourseId", "CourseId must have a minimum value of 1", () => CallSut(CreateValidRequest(p => p.CommandModel.CourseId = 0))); }
public void Test_S1IntervalTestBase_GetLength() { Assert.Equal(quad12.GetLength(), Math.PI); Assert.Equal(0, pi.GetLength()); Assert.Equal(0, mipi.GetLength()); Assert2.DoubleEqual(quad123.GetLength(), 1.5 * Math.PI); Assert.Equal(Math.Abs(quad23.GetLength()), Math.PI); Assert.Equal(full.GetLength(), S2.M_2_PI); Assert.True(empty.GetLength() < 0); }
public void Log() { void Test(double x) => Assert2.AreNearlyEqual(Math.Log(x), ElementaryFunctions2.Log(x)); Test(1.0); Test(2.0); Test(3.0); Test(0.5); Test(Math.E); }
public void Exp() { void Test(double x) => Assert2.AreNearlyEqual(Math.Exp(x), ElementaryFunctions2.Exp(x)); Test(1.0); Test(-1.0); Test(0.5); Test(2.0); Test(Math.PI); }
public void Graph_RemoveLink_Rejects_UnknownNode() { var graph = new Graph <int, int>(x => x); graph.AddLink(1, 2, 10); Assert2.Throws <InvalidOperationException>(() => graph.RemoveLink(0, 1)); Assert2.Throws <InvalidOperationException>(() => graph.RemoveLink(1, 0)); Assert2.Throws <InvalidOperationException>(() => graph.RemoveLink(0, 3)); }
public void Videos_0不正なデータ() { Assert2.ThrowsException <ArgumentException>(() => { VideosClient.GetVideosDataAsync(new NiconicoVitaContext(), new List <string>() { "lv9", "sm9" }).GetAwaiter().GetResult(); }); }
public void ExecuteValueMethod() { var executor = GetExecutorForMethod(nameof(TestObject.ValueMethod)); var result = executor.Execute( _targetObject, new object[] { 10, 20 }); Assert2.False(executor.IsMethodAsync); Assert2.Equal(30, (int)result); }
public void PropertyHelper_DoesNotChangeUnderscores() { // Arrange var anonymous = new { bar_baz2 = "foo" }; // Act + Assert var helper = Assert2.Single(PropertyHelper.GetPropertyAccessors(anonymous.GetType().GetTypeInfo())); Assert2.Equal("bar_baz2", helper.Name); }
public async Task ExecuteValueMethodAsync() { var executor = GetExecutorForMethod(nameof(TestObject.ValueMethodAsync)); var result = await executor.ExecuteAsync( _targetObject, new object[] { 10, 20 }); Assert2.True(executor.IsMethodAsync); Assert2.Equal(30, (int)result); }
public void Graph_SetLink_Rejects_UnknownNodes_Filled() { var graph = new Graph <int, int>(x => x); graph.AddDual(0, 1, 10); graph.AddDual(0, 2, 10); graph.AddLink(2, 1, 10); Assert2.Throws <InvalidOperationException>(() => graph.SetLink(1, 2, 10)); }
public void PropertyHelper_DoesNotFindStaticProperties() { // Arrange var anonymous = new Static(); // Act + Assert var helper = Assert2.Single(PropertyHelper.GetPropertyAccessors(anonymous.GetType().GetTypeInfo())); Assert2.Equal("Prop5", helper.Name); }
public void ReadShouldReadBytesFromTheBuffer() { var buffer = new SimpleByteBuffer(8); var destination = new byte[8]; buffer.Write(_BunchOfBytes, 0, 8); buffer.Read(destination, 0, 8).ShouldBe(8); Assert2.AreBytesEqual(_BunchOfBytes, 0, destination, 0, 8); }