Exemple #1
0
        public void ComplexTest()
        {
            var wtc = new WatchTestClass(2, 0);
            var watcher = new PathWatcher<WatchTestClass, int>(wtc, w => w.Child.Child.Value);

            Assert.AreEqual(0, watcher.Value);
            wtc.Update(42);
            Assert.AreEqual(42, watcher.Value);

            int i = 0;
            int rnd = int.MinValue;
            int changeCount = 10;
            int eventCount = 0;

            watcher.ValueChanged += (sender, args) =>
            {
                eventCount++;
                Assert.AreEqual(watcher.Value, rnd);
            };

            for (i = 0; i < changeCount; i++)
            {
                rnd = Util.Rnd.Next();
                wtc.Update(rnd);
                Assert.AreEqual(rnd, watcher.Value);
            }

            Assert.AreEqual(eventCount, changeCount);

            WatchTestClass.Check();
        }
Exemple #2
0
        public void ComplexTest()
        {
            var wtc     = new WatchTestClass(2, 0);
            var watcher = new PathWatcher <WatchTestClass, int>(wtc, w => w.Child.Child.Value);

            Assert.AreEqual(0, watcher.Value);
            wtc.Update(42);
            Assert.AreEqual(42, watcher.Value);

            int i           = 0;
            int rnd         = int.MinValue;
            int changeCount = 10;
            int eventCount  = 0;

            watcher.ValueChanged += (sender, args) =>
            {
                eventCount++;
                Assert.AreEqual(watcher.Value, rnd);
            };

            for (i = 0; i < changeCount; i++)
            {
                rnd = Util.Rnd.Next();
                wtc.Update(rnd);
                Assert.AreEqual(rnd, watcher.Value);
            }

            Assert.AreEqual(eventCount, changeCount);

            WatchTestClass.Check();
        }
Exemple #3
0
 public WatchTestClass(int depth, int value)
 {
     m_depth = depth;
     if (depth > 0)
     {
         m_child = new WatchTestClass(depth - 1, value);
     }
     else
     {
         m_value = value;
     }
     s_instances.Add(this);
 }
Exemple #4
0
 public WatchTestClass(int depth, int value)
 {
     m_depth = depth;
     if (depth > 0)
     {
         m_child = new WatchTestClass(depth - 1, value);
     }
     else
     {
         m_value = value;
     }
     s_instances.Add(this);
 }
Exemple #5
0
 public void Update(int value)
 {
     Debug.Assert(!m_dead);
     if (m_depth > 0)
     {
         if (Util.Rnd.Next() % 2 == 0)
         {
             Child.Kill();
             Child = new WatchTestClass(m_depth - 1, value);
         }
         else
         {
             Child.Update(value);
         }
     }
     else
     {
         Value = value;
     }
 }
Exemple #6
0
 private void Kill()
 {
     Debug.Assert(!m_dead);
     if (m_depth == 0)
     {
         Debug.Assert(m_child == null);
         m_value = null;
     }
     else
     {
         Debug.Assert(!m_value.HasValue);
         m_child.Kill();
         m_child = null;
     }
     m_dead = true;
 }
Exemple #7
0
 public void Update(int value)
 {
     Debug.Assert(!m_dead);
     if (m_depth > 0)
     {
         if (Util.Rnd.Next() % 2 == 0)
         {
             Child.Kill();
             Child = new WatchTestClass(m_depth - 1, value);
         }
         else
         {
             Child.Update(value);
         }
     }
     else
     {
         Value = value;
     }
 }