Пример #1
0
        public void Equality()
        {
            double original = 0.7286906838f;
            double maximum  = 5f;

            var compressed   = new CompressedNumber <double, Double, ushort, UShort>(original, maximum);
            var recompressed = new CompressedNumber <double, Double, ushort, UShort>(original, maximum);

            Assert.Equal(recompressed, compressed);
        }
Пример #2
0
        public void CompressDouble()
        {
            double original = 0.7286906838f;
            double maximum  = 5f;

            var    compressed   = new CompressedNumber <double, Double, ushort, UShort>(original, maximum);
            double decompressed = compressed.GetValue(maximum);

            Assert.Equal(original, decompressed, 5);
        }
Пример #3
0
        public void CompressMinValue()
        {
            int original = short.MinValue;
            int maximum  = short.MaxValue;

            var compressed   = new CompressedNumber <int, Int, short, Short>(original, maximum);
            int decompressed = compressed.GetValue(maximum);

            Assert.Equal(original, decompressed);
        }
Пример #4
0
        public void CompressFloat()
        {
            float original = 1.214814305f;
            float maximum  = 5f;

            var   compressed   = new CompressedNumber <float, Float, ushort, UShort>(original, maximum);
            float decompressed = compressed.GetValue(maximum);

            Assert.Equal(original, decompressed, 4);
        }
Пример #5
0
        public unsafe void IsBlittable()
        {
            // Requires C# 8. Please ignore if Intellisense complains. Will compile and run.
            double original = 0.7286906838f;
            double maximum  = 5f;

            var compressed = new CompressedNumber <double, Double, ushort, UShort>(original, maximum);
            var bytes      = Struct.GetBytes(compressed);

            Struct.FromArray(bytes, out CompressedNumber <double, Double, ushort, UShort> fromBytes, 0);
            var decompressed = fromBytes.GetValue(maximum);

            Assert.Equal(original, decompressed, 5);
        }