Beispiel #1
0
        public static Archive Deserialize(this Stream encoded)
        {
            var tree = new Tree();
            var map  = new Dictionary <char, long>();

            using (var reader = new BinaryReader(encoded))
            {
                var sequencesCount = reader.ReadByte();

                for (byte i = 0; i < sequencesCount; i++)
                {
                    map.Add(reader.ReadChar(), reader.ReadByte());
                }
            }

            tree.Fill(map);

            return(new Archive(encoded, tree.ToPriceMap()));
        }
Beispiel #2
0
        public void PriceMap()
        {
            var map = InitTestMap();

            tree.Fill(map);

            var price = tree.ToPriceMap();

            Assert.True(price.Count() == 7, $"Actual count is {price.Count()}");
            Assert.AreEqual(
                new Dictionary <byte, BitArray>()
            {
                { 0, new BitArray(new bool[6] {
                        false, false, false, false, false, false
                    }) },
                { 1, new BitArray(new bool[6] {
                        false, false, false, false, false, true
                    }) },
                { 2, new BitArray(new bool[5] {
                        false, false, false, false, true
                    }) },
                { 3, new BitArray(new bool[4] {
                        false, false, false, true
                    }) },
                { 4, new BitArray(new bool[3] {
                        false, false, true
                    }) },
                { 5, new BitArray(new bool[2] {
                        false, true
                    }) },
                { 6, new BitArray(new bool[1] {
                        true
                    }) },
            },
                price
                );
        }