Exemple #1
0
        public void TestSigRounding()
        {
            var v = new SignificantDigitsClamping();


            Assert.Equal(0, v.Clamp(0));
            Assert.Equal(19, v.Clamp(19));
            Assert.Equal(240, v.Clamp(239));
            Assert.Equal(2300, v.Clamp(2345));
            //Assert.Equal(2400, v.Clamp(2345));
        }
Exemple #2
0
        public void TestSigRoundingBrute()
        {
            for (var digits = 1; digits < 5; digits++)
            {
                var clamp = new SignificantDigitsClamping {
                    SignificantDigits = digits
                };

                Assert.True(
                    Enumerable.Range(0, (int)Math.Pow(10, clamp.SignificantDigits)).All(v => v == clamp.Clamp(v)));

                var count = (int)Math.Pow(10, clamp.SignificantDigits);
                Assert.Equal(Enumerable.Repeat(clamp.Clamp(26173000000), count),
                             Enumerable.Range(1, count).Select(v => clamp.Clamp(v + 26173000000)));
                Assert.Equal(Enumerable.Repeat(clamp.Clamp(33333000000), count),
                             Enumerable.Range(1, count).Select(v => clamp.Clamp(v + 33333000000)));
            }
        }