public void TestBinaryOperationsWithConversions() { DataFrame df = DataFrameTests.MakeDataFrameWithTwoColumns(10); // Add a double to an int column DataFrame dfd = df.Add(5.0f); var dtype = dfd.Column(0).DataType; Assert.True(dtype == typeof(double)); // Add a decimal to an int column DataFrame dfm = df.Add(5.0m); dtype = dfm.Column(0).DataType; Assert.True(dtype == typeof(decimal)); // int + bool should throw Assert.Throws <NotSupportedException>(() => df.Add(true)); var dataFrameColumn1 = new PrimitiveColumn <double>("Double1", Enumerable.Range(0, 10).Select(x => (double)x)); df.SetColumn(0, dataFrameColumn1); // Double + comparison ops should throw Assert.Throws <NotSupportedException>(() => df.And(true)); }
public void TestBinaryOperations() { DataFrame df = DataFrameTests.MakeTestTableWithTwoColumns(10); // Binary ops always return a copy Assert.Equal(5, df.Add(5)[0, 0]); IReadOnlyList <int> listOfInts = new List <int>() { 5, 5 }; Assert.Equal(5, df.Add(listOfInts)[0, 0]); Assert.Equal(-5, df.Subtract(5)[0, 0]); Assert.Equal(-5, df.Subtract(listOfInts)[0, 0]); Assert.Equal(5, df.Multiply(5)[1, 0]); Assert.Equal(5, df.Multiply(listOfInts)[1, 0]); Assert.Equal(1, df.Divide(5)[5, 0]); Assert.Equal(1, df.Divide(listOfInts)[5, 0]); Assert.Equal(0, df.Modulo(5)[5, 0]); Assert.Equal(0, df.Modulo(listOfInts)[5, 0]); Assert.Equal(5, df.And(5)[5, 0]); Assert.Equal(5, df.And(listOfInts)[5, 0]); Assert.Equal(5, df.Or(5)[5, 0]); Assert.Equal(5, df.Or(listOfInts)[5, 0]); Assert.Equal(0, df.Xor(5)[5, 0]); Assert.Equal(0, df.Xor(listOfInts)[5, 0]); Assert.Equal(2, df.LeftShift <int>(1)[1, 0]); Assert.Equal(1, df.RightShift <int>(1)[2, 0]); Assert.Equal(true, df.Equals(5)[5, 0]); Assert.Equal(true, df.Equals(listOfInts)[5, 0]); Assert.Equal(true, df.NotEquals(5)[4, 0]); Assert.Equal(true, df.NotEquals(listOfInts)[4, 0]); Assert.Equal(true, df.GreaterThanOrEqual(5)[6, 0]); Assert.Equal(true, df.GreaterThanOrEqual(listOfInts)[6, 0]); Assert.Equal(true, df.LessThanOrEqual(5)[4, 0]); Assert.Equal(true, df.LessThanOrEqual(listOfInts)[4, 0]); Assert.Equal(false, df.GreaterThan(5)[5, 0]); Assert.Equal(false, df.GreaterThan(listOfInts)[5, 0]); Assert.Equal(false, df.LessThan(5)[5, 0]); Assert.Equal(false, df.LessThan(listOfInts)[5, 0]); // The original DF is untouched Assert.Equal(0, df[0, 0]); }
public void TestBinaryOperationsOnBoolColumn() { var df = new DataFrame(); var dataFrameColumn1 = new PrimitiveColumn <bool>("Bool1", Enumerable.Range(0, 10).Select(x => true)); var dataFrameColumn2 = new PrimitiveColumn <bool>("Bool2", Enumerable.Range(0, 10).Select(x => true)); df.InsertColumn(0, dataFrameColumn1); df.InsertColumn(1, dataFrameColumn2); // bool + int should throw Assert.Throws <NotSupportedException>(() => df.Add(5)); // Left shift should throw Assert.Throws <NotSupportedException>(() => df.LeftShift(5)); IReadOnlyList <bool> listOfBools = new List <bool>() { true, false }; // bool equals and And should work var newdf = df.Equals(true); Assert.Equal(true, newdf[4, 0]); var newdf1 = df.Equals(listOfBools); Assert.Equal(false, newdf1[4, 1]); newdf = df.And(true); Assert.Equal(true, newdf[4, 0]); newdf1 = df.And(listOfBools); Assert.Equal(false, newdf1[4, 1]); newdf = df.Or(true); Assert.Equal(true, newdf[4, 0]); newdf1 = df.Or(listOfBools); Assert.Equal(true, newdf1[4, 1]); newdf = df.Xor(true); Assert.Equal(false, newdf[4, 0]); newdf1 = df.Xor(listOfBools); Assert.Equal(true, newdf1[4, 1]); }