public void ReadColumn1_ShouldProduceExpectedResults()
        {
            var stripeStreams = GetStripeStreamCollection();
            var decimalReader = new DecimalReader(stripeStreams, 1);
            var results       = decimalReader.Read().ToArray();

            Assert.Equal(6000, results.Length);
            for (int i = 0; i < results.Length; i++)
            {
                decimal?expected;
                if (i < 2000)
                {
                    var decimalPortion = 5 + i;
                    var wholePortion   = -1000 + i;
                    expected = decimal.Parse($"{wholePortion}.{decimalPortion}");
                }
                else if (i < 4000)
                {
                    expected = null;
                }
                else
                {
                    var decimalPortion = (i - 4000) + 1;
                    var wholePortion   = (i - 4000);
                    expected = decimal.Parse($"{wholePortion}.{decimalPortion}");
                }
                Assert.Equal(expected, results[i]);
            }
        }
        void RoundTripSingleValue(int numValues)
        {
            var pocos  = new List <SingleValuePoco>();
            var random = new Random(123);

            for (int i = 0; i < numValues; i++)
            {
                decimal wholePortion   = random.Next() % 99999;     //14-9
                decimal decimalPortion = random.Next() % 999999999; //9
                decimal value          = wholePortion + decimalPortion / 1000000000m;
                pocos.Add(new SingleValuePoco {
                    Value = value
                });
            }

            var configuration = new SerializationConfiguration()
                                .ConfigureType <SingleValuePoco>()
                                .ConfigureProperty(x => x.Value, x => { x.DecimalPrecision = 14; x.DecimalScale = 9; })
                                .Build();

            var    stream = new MemoryStream();
            Footer footer;

            StripeStreamHelper.Write(stream, pocos, out footer, configuration);
            var stripeStreams = StripeStreamHelper.GetStripeStreams(stream, footer);
            var reader        = new DecimalReader(stripeStreams, 1);
            var results       = reader.Read().ToArray();

            for (int i = 0; i < numValues; i++)
            {
                Assert.Equal(pocos[i].Value, results[i]);
            }
        }
        void RoundTripSingleValue(int numValues)
        {
            var pocos  = new List <SingleValuePoco>();
            var random = new Random(123);

            for (int i = 0; i < numValues; i++)
            {
                pocos.Add(new SingleValuePoco {
                    Value = (decimal)random.Next() / (decimal)Math.Pow(10, random.Next() % 10)
                });
            }

            var    stream = new MemoryStream();
            Footer footer;

            StripeStreamHelper.Write(stream, pocos, out footer);
            var stripeStreams = StripeStreamHelper.GetStripeStreams(stream, footer);
            var reader        = new DecimalReader(stripeStreams, 1);
            var results       = reader.Read().ToArray();

            for (int i = 0; i < numValues; i++)
            {
                Assert.Equal(pocos[i].Value, results[i]);
            }
        }
        public void read_should_use_function()
        {
            var actual = _sut.Read("some text");

            actual.Should().Be(42);
            _sentTexts.Count.Should().Be(3);
            _sentTexts[0].Should().Be("some text");
            _sentTexts[1].Should().BeNull();
            _sentTexts[2].Should().BeNull();
        }
        void RoundTripNulls(int numValues)
        {
            var pocos = new List <NullableSingleValuePoco>();

            for (int i = 0; i < numValues; i++)
            {
                pocos.Add(new NullableSingleValuePoco());
            }

            var    stream = new MemoryStream();
            Footer footer;

            StripeStreamHelper.Write(stream, pocos, out footer);
            var stripeStreams = StripeStreamHelper.GetStripeStreams(stream, footer);
            var reader        = new DecimalReader(stripeStreams, 1);
            var results       = reader.Read().ToArray();

            for (int i = 0; i < numValues; i++)
            {
                Assert.Equal(pocos[i].Value, results[i]);
            }
        }
Exemple #6
0
        // Add some non-zero constants to the mix.
        public void AddConstantsToTDB(RandoopConfiguration config)
        {
            foreach (SimpleTypeValues vs in config.simpleTypeValues)
            {
                Type type = Type.GetType(vs.simpleType);

                if (type == null)
                {
                    throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file.");
                }

                foreach (FileName fn in vs.fileNames)
                {
                    string fileName = fn.fileName;
                    if (!File.Exists(fileName))
                    {
                        throw new Common.RandoopBareExceptions.InvalidUserParamsException("Configuration file does not exist: " + fileName);
                    }

                    if (type.Equals(typeof(sbyte)))
                    {
                        SByteReader r = new SByteReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(sbyte), o));
                        }
                    }
                    else if (type.Equals(typeof(byte)))
                    {
                        ByteReader r = new ByteReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(byte), o));
                        }
                    }
                    else if (type.Equals(typeof(short)))
                    {
                        ShortReader r = new ShortReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(short), o));
                        }
                    }
                    else if (type.Equals(typeof(ushort)))
                    {
                        UshortReader r = new UshortReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(ushort), o));
                        }
                    }
                    else if (type.Equals(typeof(int)))
                    {
                        IntReader r = new IntReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(int), o));
                        }
                    }
                    else if (type.Equals(typeof(uint)))
                    {
                        UintReader r = new UintReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(uint), o));
                        }
                    }
                    else if (type.Equals(typeof(long)))
                    {
                        LongReader r = new LongReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(long), o));
                        }
                    }
                    else if (type.Equals(typeof(ulong)))
                    {
                        UlongReader r = new UlongReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(ulong), o));
                        }
                    }
                    else if (type.Equals(typeof(char)))
                    {
                        CharReader r = new CharReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(char), o));
                        }
                    }
                    else if (type.Equals(typeof(float)))
                    {
                        FloatReader r = new FloatReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(float), o));
                        }
                    }
                    else if (type.Equals(typeof(double)))
                    {
                        DoubleReader r = new DoubleReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(double), o));
                        }
                    }
                    else if (type.Equals(typeof(bool)))
                    {
                        BoolReader r = new BoolReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(bool), o));
                        }
                    }
                    else if (type.Equals(typeof(decimal)))
                    {
                        DecimalReader r = new DecimalReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(decimal), o));
                        }
                    }
                    else
                    {
                        if (!type.Equals(typeof(string)))
                        {
                            throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file.");
                        }
                        Common.StringReader r = new Common.StringReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(string), o));
                        }
                    }
                }
            }
        }
Exemple #7
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: <FILENAME>");
                return;
            }

            var filename = args[0];
            var stream   = new FileStream(filename, FileMode.Open, FileAccess.Read);
            var fileTail = new FileTail(stream);

            foreach (var stripe in fileTail.Stripes)
            {
                Console.WriteLine($"Reading stripe with {stripe.NumRows} rows");
                var stripeStreamCollection = stripe.GetStripeStreamCollection();

                if (fileTail.Footer.Types[0].Kind != ColumnTypeKind.Struct)
                {
                    throw new InvalidDataException($"The base type must be {nameof(ColumnTypeKind.Struct)}");
                }
                var names = fileTail.Footer.Types[0].FieldNames;

                for (int columnId = 1; columnId < fileTail.Footer.Types.Count; columnId++)
                {
                    var columnType = fileTail.Footer.Types[columnId];
                    var columnName = names[columnId - 1];

                    switch (columnType.Kind)
                    {
                    case ColumnTypeKind.Long:
                    case ColumnTypeKind.Int:
                    case ColumnTypeKind.Short:
                    {
                        Console.WriteLine($"Reading longs from column {columnId} ({columnName})");
                        var reader = new LongReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} longs");
                        break;
                    }

                    case ColumnTypeKind.Byte:
                    {
                        Console.WriteLine($"Reading bytes from column {columnId} ({columnName})");
                        var reader = new ByteReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} bytes");
                        break;
                    }

                    case ColumnTypeKind.Boolean:
                    {
                        Console.WriteLine($"Reading bools from column {columnId} ({columnName})");
                        var reader = new BooleanReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} bools");
                        break;
                    }

                    case ColumnTypeKind.Float:
                    {
                        Console.WriteLine($"Reading floats from column {columnId} ({columnName})");
                        var reader = new FloatReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} floats");
                        break;
                    }

                    case ColumnTypeKind.Double:
                    {
                        Console.WriteLine($"Reading doubles from column {columnId} ({columnName})");
                        var reader = new DoubleReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} doubles");
                        break;
                    }

                    case ColumnTypeKind.Binary:
                    {
                        Console.WriteLine($"Reading binary from column {columnId} ({columnName})");
                        var reader = new ColumnTypes.BinaryReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} binaries");
                        break;
                    }

                    case ColumnTypeKind.Decimal:
                    {
                        Console.WriteLine($"Reading decimals from column {columnId} ({columnName})");
                        var reader = new DecimalReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} decimals");
                        break;
                    }

                    case ColumnTypeKind.Timestamp:
                    {
                        Console.WriteLine($"Reading timestamps from column {columnId} ({columnName})");
                        var reader = new TimestampReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} timestamps");
                        break;
                    }

                    case ColumnTypeKind.Date:
                    {
                        Console.WriteLine($"Reading dates from column {columnId} ({columnName})");
                        var reader = new DateReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} dates");
                        break;
                    }

                    case ColumnTypeKind.String:
                    {
                        Console.WriteLine($"Reading strings from column {columnId} ({columnName})");
                        var reader = new ColumnTypes.StringReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} strings");
                        break;
                    }

                    default:
                        throw new NotImplementedException();
                    }
                }

                Console.WriteLine("Done reading stripe");
            }
        }
Exemple #8
0
        // Add some non-zero constants to the mix.
        public void AddConstantsToTDB(RandoopConfiguration config)
        {
            foreach (SimpleTypeValues vs in config.simpleTypeValues)
            {
                Type type = Type.GetType(vs.simpleType);

                if (type == null)
                {
                    throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file.");
                }

                foreach (FileName fn in vs.fileNames)
                {
                    string fileName = fn.fileName;
                    if (!File.Exists(fileName))
                    {
                        throw new Common.RandoopBareExceptions.InvalidUserParamsException("Configuration file does not exist: " + fileName);
                    }

                    if (type.Equals(typeof(sbyte)))
                    {
                        SByteReader r = new SByteReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(sbyte), o));
                    }
                    else if (type.Equals(typeof(byte)))
                    {
                        ByteReader r = new ByteReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(byte), o));
                    }
                    else if (type.Equals(typeof(short)))
                    {
                        ShortReader r = new ShortReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(short), o));
                    }
                    else if (type.Equals(typeof(ushort)))
                    {
                        UshortReader r = new UshortReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(ushort), o));
                    }
                    else if (type.Equals(typeof(int)))
                    {
                        IntReader r = new IntReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(int), o));
                    }
                    else if (type.Equals(typeof(uint)))
                    {
                        UintReader r = new UintReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(uint), o));
                    }
                    else if (type.Equals(typeof(long)))
                    {
                        LongReader r = new LongReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(long), o));
                    }
                    else if (type.Equals(typeof(ulong)))
                    {
                        UlongReader r = new UlongReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(ulong), o));
                    }
                    else if (type.Equals(typeof(char)))
                    {
                        CharReader r = new CharReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(char), o));
                    }
                    else if (type.Equals(typeof(float)))
                    {
                        FloatReader r = new FloatReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(float), o));
                    }
                    else if (type.Equals(typeof(double)))
                    {
                        DoubleReader r = new DoubleReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(double), o));
                    }
                    else if (type.Equals(typeof(bool)))
                    {
                        BoolReader r = new BoolReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(bool), o));
                    }
                    else if (type.Equals(typeof(decimal)))
                    {
                        DecimalReader r = new DecimalReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(decimal), o));
                    }
                    else
                    {
                        if (!type.Equals(typeof(string)))
                        {
                            throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file.");
                        }
                        Common.StringReader r = new Common.StringReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(string), o));
                    }
                }
            }
        }