Exemplo n.º 1
0
        public void Various_IntTests()
        {
            // note: this test was ported from RserveCLI.  Not in the typical Arrange/Act/Assert format

            var zero = new SexpArrayInt(0);
            var one  = new SexpArrayInt(1);
            var na   = new SexpArrayInt(SexpArrayInt.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.AsInt == 0);
            Assert.True(one.AsInt == 1);

            foreach (var a in new Sexp[] { zero, one, na })
            {
                Assert.True(!a.Equals(new SexpNull()));
            }
        }
Exemplo n.º 2
0
        public void Equals_ComparedToObjectWithDifferentValuesReadFromR_ReturnsFalse()
        {
            using (var service = new Rservice())
            {
                // Arrange
                var value1A = service.RConnection["matrix( as.integer( c( NA , 2 , 3 , -4 , -5 , 6 ) ) , ncol = 3 , byrow = TRUE )"];
                var value1B = new SexpArrayInt(new[] { SexpArrayInt.Na, -4, 2, -5, 3, 6 });

                var value2A = service.RConnection["as.integer( c( -4 , -2 , -1 ) )"];
                var value2B = new SexpArrayInt(new[] { -4, -2, -1 });

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

                var value4A = service.RConnection["integer()"];
                var value4B = new SexpArrayInt();

                // 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));
            }
        }
Exemplo n.º 3
0
        public void Equals_ComparedToSameReferencedObject_ReturnsTrue()
        {
            // Arrange
            var value1 = new SexpArrayInt();
            var value2 = new SexpArrayInt(new[] { 2, SexpArrayInt.Na, -4 });
            var value3 = new SexpArrayInt(-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));
        }
Exemplo n.º 4
0
        public void Equals_ComparedToObjectOfDifferentType_ReturnsFalse()
        {
            // Arrange
            var value1 = new SexpArrayInt(new[] { 2, -5, SexpArrayInt.Na });
            var value2 = new SexpArrayBool(true);
            var value3 = new SexpArrayDouble(new[] { 1.4, 3.6 });

            // 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
        }
Exemplo n.º 5
0
        public void Equals_ComparedToNull_ReturnsFalse()
        {
            // Arrange
            var value1 = new SexpArrayInt();
            var value2 = new SexpArrayInt(new[] { SexpArrayInt.Na, -5, 4 });
            var value3 = new SexpArrayInt(6);

            // Act & Assert
            // ReSharper disable RedundantCast
            Assert.False(value1.Equals(( SexpArrayInt )null));
            Assert.False(value1.Equals(( object )null));
            Assert.False(value2.Equals(( SexpArrayInt )null));
            Assert.False(value2.Equals(( object )null));
            Assert.False(value3.Equals(( SexpArrayInt )null));
            Assert.False(value3.Equals(( object )null));
            // ReSharper restore RedundantCast
        }
Exemplo n.º 6
0
        public void Equals_ComparedToObjectOfDifferentTypeThatCanBeCoercedIntoArrayInt_ReturnsTrue()
        {
            // Arrange
            var value1 = new SexpArrayInt(new[] { 2, -5, SexpArrayInt.Na });
            var value2 = new double[] { 2.0d, -5.0d, Convert.ToDouble(SexpArrayInt.Na) };
            var value3 = new List <int> {
                2, -5, SexpArrayInt.Na
            };
            var value4 = new SexpArrayDouble(new List <double> {
                2, -5, SexpArrayInt.Na
            });

            // 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
        }
Exemplo n.º 7
0
        public void Equals_ComparedToObjectWithDifferentValues_ReturnsFalse()
        {
            // Arrange
            var value1 = new SexpArrayInt();
            var value2 = new SexpArrayInt(-7);
            var value3 = new SexpArrayInt(new[] { -1, -6, -3 });
            var value4 = new SexpArrayInt(new[] { SexpArrayInt.Na, -6, -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));
        }
Exemplo n.º 8
0
        public void Equals_ComparedToObjectWithSameValues_ReturnsTrue()
        {
            // Arrange
            var value1A = new SexpArrayInt();
            var value1B = new SexpArrayInt();
            var value2A = new SexpArrayInt(new[] { 1, SexpArrayInt.Na, -3 });
            var value2B = new SexpArrayInt(new[] { 1, SexpArrayInt.Na, -3 });
            var value3A = new SexpArrayInt(1);
            var value3B = new SexpArrayInt(1);
            var value4A = new SexpArrayInt(new[] { -8 });
            var value4B = new SexpArrayInt(-8);

            // Act & Assert
            Assert.True(value1A.Equals(value1B));
            Assert.True(value2A.Equals(value2B));
            Assert.True(value3A.Equals(value3B));
            Assert.True(value4A.Equals(value4B));
        }
        public void Various_IntTests()
        {
            // note: this test was ported from RserveCLI.  Not in the typical Arrange/Act/Assert format

            var zero = new SexpArrayInt( 0 );
            var one = new SexpArrayInt( 1 );
            var na = new SexpArrayInt( SexpArrayInt.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.AsInt == 0 );
            Assert.True( one.AsInt == 1 );

            foreach ( var a in new Sexp[] { zero , one , na } )
            {
                Assert.True( !a.Equals( new SexpNull() ) );
            }
        }
Exemplo n.º 10
0
        public void Equals_ComparedToObjectWithSameValues_ReturnsTrue()
        {
            // Arrange
            var value1A = new SexpArrayInt();
            var value1B = new SexpArrayInt();
            var value2A = new SexpArrayInt( new[] { 1 , SexpArrayInt.Na , -3 } );
            var value2B = new SexpArrayInt( new[] { 1 , SexpArrayInt.Na , -3 } );
            var value3A = new SexpArrayInt( 1 );
            var value3B = new SexpArrayInt( 1 );
            var value4A = new SexpArrayInt( new[] { -8 } );
            var value4B = new SexpArrayInt( -8 );

            // Act & Assert
            Assert.True( value1A.Equals( value1B ) );
            Assert.True( value2A.Equals( value2B ) );
            Assert.True( value3A.Equals( value3B ) );
            Assert.True( value4A.Equals( value4B ) );
        }
Exemplo n.º 11
0
        public void Equals_ComparedToSameReferencedObject_ReturnsTrue()
        {
            // Arrange
            var value1 = new SexpArrayInt();
            var value2 = new SexpArrayInt( new[] { 2 , SexpArrayInt.Na , -4 } );
            var value3 = new SexpArrayInt( -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 ) );
        }
Exemplo n.º 12
0
        public void Equals_ComparedToObjectWithSameValuesReadFromR_ReturnsFalse()
        {
            using ( var service = new Rservice() )
            {
                // Arrange
                var value1A = service.RConnection[ "matrix( as.integer( c( 1 , 2 , 3 , -4 , -5 , NA ) ) , ncol = 3 , byrow = TRUE )" ];
                var value1B = new SexpArrayInt( new[] { 1 , -4 , 2 , -5 , 3 , SexpArrayInt.Na } );

                var value2A = service.RConnection[ "as.integer( c( -4 , -2 , -1 ) )" ];
                var value2B = new SexpArrayInt( new[] { -4 , -2 , -1 } );

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

                var value4A = service.RConnection[ "integer()" ];
                var value4B = new SexpArrayInt();

                // 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 ) );
            }
        }
Exemplo n.º 13
0
        public void Equals_ComparedToObjectWithDifferentValues_ReturnsFalse()
        {
            // Arrange
            var value1 = new SexpArrayInt();
            var value2 = new SexpArrayInt( -7 );
            var value3 = new SexpArrayInt( new[] { -1 , -6 , -3 } );
            var value4 = new SexpArrayInt( new[] { SexpArrayInt.Na , -6 , -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 ) );
        }
Exemplo n.º 14
0
        public void Equals_ComparedToObjectOfDifferentType_ReturnsFalse()
        {
            // Arrange
            var value1 = new SexpArrayInt( new[] { 2 , -5 , SexpArrayInt.Na } );
            var value2 = new SexpArrayBool( true );
            var value3 = new SexpArrayDouble( new[] { 1.4 , 3.6 } );

            // 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
        }
Exemplo n.º 15
0
        public void Equals_ComparedToObjectOfDifferentTypeThatCanBeCoercedIntoArrayInt_ReturnsTrue()
        {
            // Arrange
            var value1 = new SexpArrayInt( new[] { 2 , -5 , SexpArrayInt.Na } );
            var value2 = new double[] { 2.0d , -5.0d , Convert.ToDouble( SexpArrayInt.Na ) };
            var value3 = new List<int> { 2 , -5 , SexpArrayInt.Na };
            var value4 = new SexpArrayDouble( new List<double> { 2 , -5 , SexpArrayInt.Na } );

            // 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
        }
Exemplo n.º 16
0
        public void Equals_ComparedToNull_ReturnsFalse()
        {
            // Arrange
            var value1 = new SexpArrayInt();
            var value2 = new SexpArrayInt( new[] { SexpArrayInt.Na , -5 , 4 } );
            var value3 = new SexpArrayInt( 6 );

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