예제 #1
0
            public void adding_null_vector_throws()
            {
                var     left  = new VectorD(3);
                VectorD right = null;

                Assert.Throws <ArgumentNullException>(() => left.GetSum(right));
            }
예제 #2
0
            public void adding_vectors_of_different_size_throws()
            {
                var left  = new VectorD(3);
                var right = new VectorD(4);

                Assert.NotEqual(left.Dimensions, right.Dimensions);

                Assert.Throws <ArgumentOutOfRangeException>(() => left.GetSum(right));
            }
예제 #3
0
            public void adding_vectors_does_not_mutate_operands()
            {
                var left = new VectorD(3);

                left.Set(0, 1);
                left.Set(1, 3);
                left.Set(2, -4);
                var expectedLeft = new VectorD(left);
                var right        = new VectorD(3);

                right.Set(0, -10);
                right.Set(1, 4);
                right.Set(2, -20);
                var expectedRight = new VectorD(right);

                left.GetSum(right);

                Assert.Equal(expectedRight, right);
                Assert.Equal(expectedLeft, left);
            }
예제 #4
0
            public void can_add_vectors_of_same_size()
            {
                var left = new VectorD(3);

                left.Set(0, 1);
                left.Set(1, 3);
                left.Set(2, -4);
                var right = new VectorD(3);

                right.Set(0, -10);
                right.Set(1, 4);
                right.Set(2, -20);
                var expected = new VectorD(3);

                expected.Set(0, -9);
                expected.Set(1, 7);
                expected.Set(2, -24);

                var actual = left.GetSum(right);

                Assert.Equal(expected, actual);
            }