Ejemplo n.º 1
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
        }
Ejemplo n.º 2
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()));
            }
        }
Ejemplo n.º 3
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));
            }
        }
Ejemplo n.º 4
0
        public void AsInts_SexpConstructedUsingConstructorOrMake_ReturnsSameSetOfInts()
        {
            // Arrange
            var values1 = new int[1, 1] {
                { 2 }
            };
            var values2 = new int[3, 4] {
                { 8, 2, 7, SexpArrayInt.Na }, { 0, -9, 5, -2 }, { 1, -4, -3, -8 }
            };
            const int values3 = -5;
            var       values4 = new List <int> {
                4, 5, 6
            };

            // Act
            Sexp sexp1 = Sexp.Make(values1);
            Sexp sexp2 = Sexp.Make(values2);
            Sexp sexp3 = new SexpArrayInt(values3);
            Sexp sexp4 = new SexpArrayInt(values4);
            Sexp sexp5 = new SexpArrayInt();

            // Assert
            Assert.Equal(new[] { 2 }, sexp1.AsInts);
            Assert.Equal(new[] { 8, 0, 1, 2, -9, -4, 7, 5, -3, SexpArrayInt.Na, -2, -8 }, sexp2.AsInts);
            Assert.Equal(new[] { -5 }, sexp3.AsInts);
            Assert.Equal(new[] { 4, 5, 6 }, sexp4.AsInts);
            Assert.Equal(new int[] { }, sexp5.AsInts);
        }
Ejemplo n.º 5
0
        public void IsNa_NaValueInConstructor_ReturnTrue()
        {
            // Arrange
            var sexp1 = new SexpArrayInt(SexpArrayInt.Na);
            var sexp2 = new SexpArrayInt(new[] { SexpArrayInt.Na });

            // Act & Assert
            Assert.True(sexp1.IsNa);
            Assert.True(sexp2.IsNa);
        }
Ejemplo n.º 6
0
        public void IsNa_NotNa_ReturnFalse()
        {
            // Arrange
            var sexp1 = new SexpArrayInt(3);
            var sexp2 = new SexpArrayInt(new[] { -8 });

            // Act & Assert
            Assert.False(sexp1.IsNa);
            Assert.False(sexp2.IsNa);
        }
Ejemplo n.º 7
0
        public void IsNa_SexpContainsZeroOrMultipleValues_ThrowsNotSupportedException()
        {
            // Arrange
            var sexp1 = new SexpArrayInt();
            var sexp2 = new SexpArrayInt(new int[] { });
            var sexp3 = new SexpArrayInt(new[] { SexpArrayInt.Na, 4 });
            var sexp4 = new SexpArrayInt(new[] { 4, -9 });

            // Act & Assert
            Assert.Throws <NotSupportedException>(() => sexp1.IsNa);
            Assert.Throws <NotSupportedException>(() => sexp2.IsNa);
            Assert.Throws <NotSupportedException>(() => sexp3.IsNa);
            Assert.Throws <NotSupportedException>(() => sexp4.IsNa);
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
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
        }
Ejemplo n.º 10
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
        }
Ejemplo n.º 11
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));
        }
Ejemplo n.º 12
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));
        }
Ejemplo n.º 13
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
        }
Ejemplo n.º 14
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
        }
Ejemplo n.º 15
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 ) );
        }
Ejemplo n.º 16
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 ) );
            }
        }
Ejemplo n.º 17
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 ) );
        }
Ejemplo n.º 18
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 ) );
        }
Ejemplo n.º 19
0
        public void IsNa_NaValueInConstructor_ReturnTrue()
        {
            // Arrange
            var sexp1 = new SexpArrayInt( SexpArrayInt.Na );
            var sexp2 = new SexpArrayInt( new[] { SexpArrayInt.Na } );

            // Act & Assert
            Assert.True( sexp1.IsNa );
            Assert.True( sexp2.IsNa );
        }
Ejemplo n.º 20
0
        public void IsNa_NotNa_ReturnFalse()
        {
            // Arrange
            var sexp1 = new SexpArrayInt( 3 );
            var sexp2 = new SexpArrayInt( new[] { -8 } );

            // Act & Assert
            Assert.False( sexp1.IsNa );
            Assert.False( sexp2.IsNa );
        }
Ejemplo n.º 21
0
        public void IsNa_SexpContainsZeroOrMultipleValues_ThrowsNotSupportedException()
        {
            // Arrange
            var sexp1 = new SexpArrayInt();
            var sexp2 = new SexpArrayInt( new int[] { } );
            var sexp3 = new SexpArrayInt( new[] { SexpArrayInt.Na , 4 } );
            var sexp4 = new SexpArrayInt( new[] { 4 , -9 } );

            // Act & Assert
            Assert.Throws<NotSupportedException>( () => sexp1.IsNa );
            Assert.Throws<NotSupportedException>( () => sexp2.IsNa );
            Assert.Throws<NotSupportedException>( () => sexp3.IsNa );
            Assert.Throws<NotSupportedException>( () => sexp4.IsNa );
        }
Ejemplo n.º 22
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
        }
        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
        }
Ejemplo n.º 24
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() ) );
            }
        }
        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
        }
Ejemplo n.º 26
0
        public void AsInts_SexpConstructedUsingConstructorOrMake_ReturnsSameSetOfInts()
        {
            // Arrange
            var values1 = new int[ 1 , 1 ] { { 2 } };
            var values2 = new int[ 3 , 4 ] { { 8 , 2 , 7 , SexpArrayInt.Na } , { 0 , -9 , 5 , -2 } , { 1 , -4 , -3 , -8 } };
            const int values3 = -5;
            var values4 = new List<int> { 4 , 5 , 6 };

            // Act
            Sexp sexp1 = Sexp.Make( values1 );
            Sexp sexp2 = Sexp.Make( values2 );
            Sexp sexp3 = new SexpArrayInt( values3 );
            Sexp sexp4 = new SexpArrayInt( values4 );
            Sexp sexp5 = new SexpArrayInt();

            // Assert
            Assert.Equal( new[] { 2 } , sexp1.AsInts );
            Assert.Equal( new[] { 8 , 0 , 1 , 2 , -9 , -4 , 7 , 5 , -3 , SexpArrayInt.Na , -2 , -8 } , sexp2.AsInts );
            Assert.Equal( new[] { -5 } , sexp3.AsInts );
            Assert.Equal( new[] { 4 , 5 , 6 } , sexp4.AsInts );
            Assert.Equal( new int[] { } , sexp5.AsInts );
        }