示例#1
0
        public void TestComputations()
        {
            DataFrame df = MakeDataFrameWithAllColumnTypes(10);

            df["Int"][0] = -10;
            Assert.Equal(-10, df["Int"][0]);

            df["Int"].Abs();
            Assert.Equal(10, df["Int"][0]);

            Assert.Throws <NotSupportedException>(() => df["Byte"].All());
            Assert.Throws <NotSupportedException>(() => df["Byte"].Any());
            Assert.Throws <NotSupportedException>(() => df["Char"].All());
            Assert.Throws <NotSupportedException>(() => df["Char"].Any());
            Assert.Throws <NotSupportedException>(() => df["Decimal"].All());
            Assert.Throws <NotSupportedException>(() => df["Decimal"].Any());
            Assert.Throws <NotSupportedException>(() => df["Double"].All());
            Assert.Throws <NotSupportedException>(() => df["Double"].Any());
            Assert.Throws <NotSupportedException>(() => df["Float"].All());
            Assert.Throws <NotSupportedException>(() => df["Float"].Any());
            Assert.Throws <NotSupportedException>(() => df["Int"].All());
            Assert.Throws <NotSupportedException>(() => df["Int"].Any());
            Assert.Throws <NotSupportedException>(() => df["Long"].All());
            Assert.Throws <NotSupportedException>(() => df["Long"].Any());
            Assert.Throws <NotSupportedException>(() => df["Sbyte"].All());
            Assert.Throws <NotSupportedException>(() => df["Sbyte"].Any());
            Assert.Throws <NotSupportedException>(() => df["Short"].All());
            Assert.Throws <NotSupportedException>(() => df["Short"].Any());
            Assert.Throws <NotSupportedException>(() => df["Uint"].All());
            Assert.Throws <NotSupportedException>(() => df["Uint"].Any());
            Assert.Throws <NotSupportedException>(() => df["Ulong"].All());
            Assert.Throws <NotSupportedException>(() => df["Ulong"].Any());
            Assert.Throws <NotSupportedException>(() => df["Ushort"].All());
            Assert.Throws <NotSupportedException>(() => df["Ushort"].Any());

            bool any = df["Bool"].Any();
            bool all = df["Bool"].All();

            Assert.True(any);
            Assert.False(all);

            // Test the computation results
            df["Double"][0] = 100.0;
            df["Double"].CumulativeMax();
            Assert.Equal(100.0, df["Double"][9]);

            df["Float"][0] = -10.0f;
            df["Float"].CumulativeMin();
            Assert.Equal(-10.0f, df["Float"][9]);

            df["Uint"].CumulativeProduct();
            Assert.Equal((uint)0, df["Uint"][9]);

            df["Ushort"].CumulativeSum();
            Assert.Equal((ushort)45, df["Ushort"][9]);

            Assert.Equal(100.0, df["Double"].Max());
            Assert.Equal(-10.0f, df["Float"].Min());
            Assert.Equal((uint)0, df["Uint"].Product());
            Assert.Equal((ushort)165, df["Ushort"].Sum());

            df["Double"][0] = 100.1;
            Assert.Equal(100.1, df["Double"][0]);
            df["Double"].Round();
            Assert.Equal(100.0, df["Double"][0]);

            // Test that none of the numeric column types throw
            for (int i = 0; i < df.ColumnCount; i++)
            {
                BaseColumn column = df.Column(i);
                if (column.DataType == typeof(bool))
                {
                    Assert.Throws <NotSupportedException>(() => column.CumulativeMax());
                    Assert.Throws <NotSupportedException>(() => column.CumulativeMin());
                    Assert.Throws <NotSupportedException>(() => column.CumulativeProduct());
                    Assert.Throws <NotSupportedException>(() => column.CumulativeSum());
                    Assert.Throws <NotSupportedException>(() => column.Max());
                    Assert.Throws <NotSupportedException>(() => column.Min());
                    Assert.Throws <NotSupportedException>(() => column.Product());
                    Assert.Throws <NotSupportedException>(() => column.Sum());
                    continue;
                }
                else if (column.DataType == typeof(string))
                {
                    Assert.Throws <NotImplementedException>(() => column.CumulativeMax());
                    Assert.Throws <NotImplementedException>(() => column.CumulativeMin());
                    Assert.Throws <NotImplementedException>(() => column.CumulativeProduct());
                    Assert.Throws <NotImplementedException>(() => column.CumulativeSum());
                    Assert.Throws <NotImplementedException>(() => column.Max());
                    Assert.Throws <NotImplementedException>(() => column.Min());
                    Assert.Throws <NotImplementedException>(() => column.Product());
                    Assert.Throws <NotImplementedException>(() => column.Sum());
                    continue;
                }
                column.CumulativeMax();
                column.CumulativeMin();
                column.CumulativeProduct();
                column.CumulativeSum();
                column.Max();
                column.Min();
                column.Product();
                column.Sum();
            }
        }
示例#2
0
 public object Sum()
 {
     return(_column0.Sum());
 }