Exemplo n.º 1
0
 public void GrayCodeConstructorTest()
 {
     double         value       = 0.2;
     double         min         = 0F;
     double         max         = 2;
     uint           bitAccuracy = 8;
     GrayCodeConfig config      = new GrayCodeConfig(min, max, bitAccuracy);
     GrayCode       target      = new GrayCode(value, config);
 }
Exemplo n.º 2
0
        public void ValueUintGrayCodeTest()
        {
            double         value       = 0.5;
            double         min         = -1.0;
            double         max         = 1.0;
            uint           bitAccuracy = 8;
            GrayCodeConfig config      = new GrayCodeConfig(min, max, bitAccuracy);
            GrayCode       target      = new GrayCode(value, config);
            uint           expected    = 224;
            uint           actual      = target.DecimalCode;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
        public void ValueTest()
        {
            double         value       = 1.0;
            double         min         = 0.5;
            double         max         = 4;
            uint           bitAccuracy = 8;
            GrayCodeConfig config      = new GrayCodeConfig(min, max, bitAccuracy);
            GrayCode       target      = new GrayCode(value, config);
            double         expected    = value;
            double         actual;

            actual = target.Value;
            Assert.IsTrue(Math.Abs(actual - expected) <= 2 / (Math.Pow(2, bitAccuracy) - 1));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Генерирует фактор со случайным значением
 /// </summary>
 /// <param name="config">Конфигурация фактора</param>
 /// <returns>Случайный фактор</returns>
 private GrayCode GenerateRandomFactor(GrayCodeConfig config)
 {
     try
     {
         var randomFactor  = new GrayCode(0, config);
         var decimalNumber = (uint)_random.Next(0, (int)(Math.Pow(2, config.Accuracy) - 1));
         randomFactor.DecimalCode = decimalNumber;
         return(randomFactor);
     }
     catch (Exception e)
     {
         throw new Exception("Cant generate random factor", e);
     }
 }
Exemplo n.º 5
0
        public void BinaryGTest()
        {
            double         value       = 0.5;
            double         min         = -1.0;
            double         max         = 1.0;
            uint           bitAccuracy = 8;
            GrayCodeConfig config      = new GrayCodeConfig(min, max, bitAccuracy);
            GrayCode       target      = new GrayCode(value, config);
            string         expected    = "11100000";
            string         actual;

            //target.StringCode = expected;
            actual = target.StringCode;
            Assert.AreEqual(expected, actual);
        }