Пример #1
0
        public void Various_DoubleTest()
        {
            // note: this test was ported from RserveCLI.  Not in the typical Arrange/Act/Assert format
            var zero = new SexpArrayDouble(0.0);
            var one  = new SexpArrayDouble(1.0);
            var na   = new SexpArrayDouble(SexpArrayDouble.Na);

            // ReSharper disable EqualExpressionComparison
            Assert.True(zero.Equals(zero));
            Assert.True(one.Equals(one));
            Assert.True(na.Equals(na));

            // ReSharper restore EqualExpressionComparison
            Assert.True(!zero.Equals(one));
            Assert.True(!zero.Equals(na));
            Assert.True(!one.Equals(na));
            Assert.True(zero.Equals(0));
            Assert.True(one.Equals(1));
            Assert.True(na.IsNa);
            Assert.True(zero.AsDouble == 0.0);
            Assert.True(one.AsDouble == 1.0);
            Assert.True(zero.AsInt == 0);
            Assert.True(one.AsInt == 1);
            Assert.True(double.IsNaN(na.AsDouble));

            foreach (var a in new Sexp[] { zero, one, na })
            {
                Assert.True(!a.Equals(new SexpNull()));
            }
        }
Пример #2
0
        public void Equals_ComparedToObjectWithDifferentValuesReadFromR_ReturnsFalse()
        {
            using (var service = new Rservice())
            {
                // Arrange
                var value1A = service.RConnection["matrix( c( 1.1 , 2.6 , NA , -4.2 , -5.8 , 6.3 ) , ncol = 3 , byrow = TRUE )"];
                var value1B = new SexpArrayDouble(new[] { 1.1, -4.2, 2.6, -5.8, double.NaN, 6.3 });

                var value2A = service.RConnection["c( -4.4 , -2.2 , -1 )"];
                var value2B = new SexpArrayDouble(new[] { -4.4, -2.2, -1 });

                var value3A = service.RConnection["-.9"];
                var value3B = new SexpArrayDouble(-.9);

                var value4A = service.RConnection["numeric()"];
                var value4B = new SexpArrayDouble();

                // Act & Assert
                Assert.False(value3B.Equals(value2A));
                Assert.False(value2A.Equals(value4A));
                Assert.False(value3B.Equals(value2B));
                Assert.False(value4A.Equals(value1B));
                Assert.False(value3B.Equals(value1A));
                Assert.False(value4A.Equals(value3A));
                Assert.False(value1A.Equals(value2B));
                Assert.False(value2A.Equals(value3A));
                Assert.False(value3A.Equals(value1A));
                Assert.False(value1B.Equals(value4B));
            }
        }
Пример #3
0
        public void Equals_ComparedToSameReferencedObject_ReturnsTrue()
        {
            // Arrange
            var value1 = new SexpArrayDouble();
            var value2 = new SexpArrayDouble(new[] { 2.3, double.NaN, 4 });
            var value3 = new SexpArrayDouble(-6.6);

            // Act & Assert
            Assert.True(value1.Equals(value1));
            Assert.True(value1.Equals(( object )value1));
            Assert.True(value2.Equals(value2));
            Assert.True(value2.Equals(( object )value2));
            Assert.True(value3.Equals(value3));
            Assert.True(value3.Equals(( object )value3));
        }
Пример #4
0
        public void Equals_ComparedToObjectOfDifferentType_ReturnsFalse()
        {
            // Arrange
            var value1 = new SexpArrayDouble(new[] { 2.3, double.NaN, 4 });
            var value2 = new SexpArrayBool(true);
            var value3 = new SexpArrayInt(new[] { 1, 3 });

            // Act & Assert

            // ReSharper disable RedundantCast
            Assert.False(value1.Equals(value2));
            Assert.False(value1.Equals(( object )value2));
            Assert.False(value1.Equals(value3));
            Assert.False(value1.Equals(( object )value3));
            // ReSharper restore RedundantCast
        }
Пример #5
0
        public void Equals_ComparedToNull_ReturnsFalse()
        {
            // Arrange
            var value1 = new SexpArrayDouble();
            var value2 = new SexpArrayDouble(new[] { 2.3, double.NaN, 4 });
            var value3 = new SexpArrayDouble(6.5);

            // Act & Assert

            // ReSharper disable RedundantCast
            Assert.False(value1.Equals(( SexpArrayDouble )null));
            Assert.False(value1.Equals(( object )null));
            Assert.False(value2.Equals(( SexpArrayDouble )null));
            Assert.False(value2.Equals(( object )null));
            Assert.False(value3.Equals(( SexpArrayDouble )null));
            Assert.False(value3.Equals(( object )null));
            // ReSharper restore RedundantCast
        }
Пример #6
0
        public void Equals_ComparedToObjectWithDifferentValues_ReturnsFalse()
        {
            // Arrange
            var value1 = new SexpArrayDouble();
            var value2 = new SexpArrayDouble(-7.7);
            var value3 = new SexpArrayDouble(new[] { -1.2, -6.4, -3.3 });
            var value4 = new SexpArrayDouble(new[] { 1.2, double.NaN, -3.3 });

            // Act & Assert
            Assert.False(value1.Equals(value2));
            Assert.False(value1.Equals(value3));
            Assert.False(value1.Equals(value4));
            Assert.False(value2.Equals(value1));
            Assert.False(value2.Equals(value3));
            Assert.False(value2.Equals(value4));
            Assert.False(value3.Equals(value1));
            Assert.False(value3.Equals(value2));
            Assert.False(value3.Equals(value4));
            Assert.False(value4.Equals(value1));
            Assert.False(value4.Equals(value2));
            Assert.False(value4.Equals(value3));
        }
Пример #7
0
        public void Equals_ComparedToObjectWithSameValues_ReturnsTrue()
        {
            // Arrange
            var value1A = new SexpArrayDouble();
            var value1B = new SexpArrayDouble();
            var value2A = new SexpArrayDouble(new[] { 1.2, double.NaN, -3.3 });
            var value2B = new SexpArrayDouble(new[] { 1.2, double.NaN, -3.3 });
            var value3A = new SexpArrayDouble(1.4);
            var value3B = new SexpArrayDouble(1.4);
            var value4A = new SexpArrayDouble(new[] { -8.4 });
            var value4B = new SexpArrayDouble(-8.4);

            // Act & Assert
            Assert.True(value1A.Equals(value1B));
            Assert.True(value2A.Equals(value2B));
            Assert.True(value3A.Equals(value3B));
            Assert.True(value4A.Equals(value4B));
        }
Пример #8
0
        public void Equals_ComparedToObjectOfDifferentTypeThatCanBeCoercedIntoArrayDouble_ReturnsTrue()
        {
            // Arrange
            var value1 = new SexpArrayDouble(new[] { 4d, -2d, -3d });
            var value2 = new List <double> {
                4, -2, -3
            };
            var value3 = new int[] { 4, -2, -3 };
            var value4 = new SexpArrayInt(new int[] { 4, -2, -3 });

            // Act & Assert

            // ReSharper disable RedundantCast
            Assert.True(value1.Equals(value2));
            Assert.True(value1.Equals(( object )value2));

            Assert.True(value1.Equals(value3));
            Assert.True(value1.Equals(( object )value3));

            Assert.True(value1.Equals(value4));
            Assert.True(value1.Equals(( object )value4));
            // ReSharper restore RedundantCast
        }
        public void Various_DoubleTest()
        {
            // note: this test was ported from RserveCLI.  Not in the typical Arrange/Act/Assert format
            var zero = new SexpArrayDouble( 0.0 );
            var one = new SexpArrayDouble( 1.0 );
            var na = new SexpArrayDouble( SexpArrayDouble.Na );

            // ReSharper disable EqualExpressionComparison
            Assert.True( zero.Equals( zero ) );
            Assert.True( one.Equals( one ) );
            Assert.True( na.Equals( na ) );

            // ReSharper restore EqualExpressionComparison
            Assert.True( !zero.Equals( one ) );
            Assert.True( !zero.Equals( na ) );
            Assert.True( !one.Equals( na ) );
            Assert.True( zero.Equals( 0 ) );
            Assert.True( one.Equals( 1 ) );
            Assert.True( na.IsNa );
            Assert.True( zero.AsDouble == 0.0 );
            Assert.True( one.AsDouble == 1.0 );
            Assert.True( zero.AsInt == 0 );
            Assert.True( one.AsInt == 1 );
            Assert.True( double.IsNaN( na.AsDouble ) );

            foreach ( var a in new Sexp[] { zero , one , na } )
            {
                Assert.True( !a.Equals( new SexpNull() ) );
            }
        }
        public void Equals_ComparedToSameReferencedObject_ReturnsTrue()
        {
            // Arrange
            var value1 = new SexpArrayDouble();
            var value2 = new SexpArrayDouble( new[] { 2.3 , double.NaN , 4 } );
            var value3 = new SexpArrayDouble( -6.6 );

            // Act & Assert
            Assert.True( value1.Equals( value1 ) );
            Assert.True( value1.Equals( ( object )value1 ) );
            Assert.True( value2.Equals( value2 ) );
            Assert.True( value2.Equals( ( object )value2 ) );
            Assert.True( value3.Equals( value3 ) );
            Assert.True( value3.Equals( ( object )value3 ) );
        }
        public void Equals_ComparedToObjectWithSameValues_ReturnsTrue()
        {
            // Arrange
            var value1A = new SexpArrayDouble();
            var value1B = new SexpArrayDouble();
            var value2A = new SexpArrayDouble( new[] { 1.2 , double.NaN , -3.3 } );
            var value2B = new SexpArrayDouble( new[] { 1.2 , double.NaN , -3.3 } );
            var value3A = new SexpArrayDouble( 1.4 );
            var value3B = new SexpArrayDouble( 1.4 );
            var value4A = new SexpArrayDouble( new[] { -8.4 } );
            var value4B = new SexpArrayDouble( -8.4 );

            // Act & Assert
            Assert.True( value1A.Equals( value1B ) );
            Assert.True( value2A.Equals( value2B ) );
            Assert.True( value3A.Equals( value3B ) );
            Assert.True( value4A.Equals( value4B ) );
        }
        public void Equals_ComparedToObjectWithSameValuesReadFromR_ReturnsFalse()
        {
            using ( var service = new Rservice() )
            {
                // Arrange
                var value1A = service.RConnection[ "matrix( c( 1.1 , 2.6 , 3.9 , -4.2 , NA , 6.3 ) , ncol = 3 , byrow = TRUE )" ];
                var value1B = new SexpArrayDouble( new[] { 1.1 , -4.2 , 2.6 , double.NaN , 3.9 , 6.3 } );

                var value2A = service.RConnection[ "c( -4.4 , -2.2 , -1 )" ];
                var value2B = new SexpArrayDouble( new[] { -4.4 , -2.2 , -1 } );

                var value3A = service.RConnection[ "-.9" ];
                var value3B = new SexpArrayDouble( -.9 );

                var value4A = service.RConnection[ "numeric()" ];
                var value4B = new SexpArrayDouble();

                // Act & Assert
                Assert.True( value1A.Equals( value1B ) );
                Assert.True( value1B.Equals( value1A ) );
                Assert.True( value2A.Equals( value2B ) );
                Assert.True( value2B.Equals( value2A ) );
                Assert.True( value3A.Equals( value3B ) );
                Assert.True( value3B.Equals( value3A ) );
                Assert.True( value4A.Equals( value4B ) );
                Assert.True( value4B.Equals( value4A ) );
            }
        }
        public void Equals_ComparedToObjectWithDifferentValues_ReturnsFalse()
        {
            // Arrange
            var value1 = new SexpArrayDouble();
            var value2 = new SexpArrayDouble( -7.7 );
            var value3 = new SexpArrayDouble( new[] { -1.2 , -6.4 , -3.3 } );
            var value4 = new SexpArrayDouble( new[] { 1.2 , double.NaN , -3.3 } );

            // Act & Assert
            Assert.False( value1.Equals( value2 ) );
            Assert.False( value1.Equals( value3 ) );
            Assert.False( value1.Equals( value4 ) );
            Assert.False( value2.Equals( value1 ) );
            Assert.False( value2.Equals( value3 ) );
            Assert.False( value2.Equals( value4 ) );
            Assert.False( value3.Equals( value1 ) );
            Assert.False( value3.Equals( value2 ) );
            Assert.False( value3.Equals( value4 ) );
            Assert.False( value4.Equals( value1 ) );
            Assert.False( value4.Equals( value2 ) );
            Assert.False( value4.Equals( value3 ) );
        }
        public void Equals_ComparedToObjectOfDifferentType_ReturnsFalse()
        {
            // Arrange
            var value1 = new SexpArrayDouble( new[] { 2.3 , double.NaN , 4 } );
            var value2 = new SexpArrayBool( true );
            var value3 = new SexpArrayInt( new[] { 1 , 3 } );

            // Act & Assert

            // ReSharper disable RedundantCast
            Assert.False( value1.Equals( value2 ) );
            Assert.False( value1.Equals( ( object )value2 ) );
            Assert.False( value1.Equals( value3 ) );
            Assert.False( value1.Equals( ( object )value3 ) );
            // ReSharper restore RedundantCast
        }
        public void Equals_ComparedToObjectOfDifferentTypeThatCanBeCoercedIntoArrayDouble_ReturnsTrue()
        {
            // Arrange
            var value1 = new SexpArrayDouble( new[] { 4d , -2d , -3d } );
            var value2 = new List<double> { 4 , -2 , -3 };
            var value3 = new int[] { 4 , -2 , -3 };
            var value4 = new SexpArrayInt( new int[] { 4 , -2 , -3 } );

            // Act & Assert

            // ReSharper disable RedundantCast
            Assert.True( value1.Equals( value2 ) );
            Assert.True( value1.Equals( ( object )value2 ) );

            Assert.True( value1.Equals( value3 ) );
            Assert.True( value1.Equals( ( object )value3 ) );

            Assert.True( value1.Equals( value4 ) );
            Assert.True( value1.Equals( ( object )value4 ) );
            // ReSharper restore RedundantCast
        }
        public void Equals_ComparedToNull_ReturnsFalse()
        {
            // Arrange
            var value1 = new SexpArrayDouble();
            var value2 = new SexpArrayDouble( new[] { 2.3 , double.NaN , 4 } );
            var value3 = new SexpArrayDouble( 6.5 );

            // Act & Assert

            // ReSharper disable RedundantCast
            Assert.False( value1.Equals( ( SexpArrayDouble )null ) );
            Assert.False( value1.Equals( ( object )null ) );
            Assert.False( value2.Equals( ( SexpArrayDouble )null ) );
            Assert.False( value2.Equals( ( object )null ) );
            Assert.False( value3.Equals( ( SexpArrayDouble )null ) );
            Assert.False( value3.Equals( ( object )null ) );
            // ReSharper restore RedundantCast
        }