Example #1
0
 protected ImmutableState(ImmutableState prev, ushort addr, ushort value)
 {
     _memory = prev._memory;
     _regs = prev._regs;
     _memoryMap = prev._memoryMap;
     var deviceId = prev._memoryMap[addr];
     if (deviceId == null) {
         _memory = _memory.Set(addr, value);
         _deviceStates = prev._deviceStates;
     } else {
         _deviceStates = new Dictionary<string, DeviceState>(prev._deviceStates);
         _deviceStates[deviceId] = prev._deviceStates[deviceId].Write(addr, value);
     }
 }
        public void GetAndSet_ManyElementArray_CorrectElementsReturned()
        {
            var array = new PersistentArray<int>(100);
            for (int i=0; i < 100; ++i) {
                array = array.Set(i, 2 * i);
            }

            for (int i=0; i < 100; ++i) {
                Assert.AreEqual(2 * i, array[i]);
            }

            var array2 = array;
            for (int i=0; i < 100; ++i) {
                array2 = array2.Set(i, array[99 - i]);
            }

            for (int i=99; i >= 0; --i) {
                Assert.AreEqual(2 * i, array2[99 - i]);
            }
        }
 public void Set_LengthOneArray_OldValueIdentical()
 {
     var array = new PersistentArray<string>(1);
     var array2 = array.Set(0, "foo");
     Assert.AreEqual(null, array[0]);
 }
 public void Set_LengthOneArray_NewValueCorrect()
 {
     var array = new PersistentArray<string>(1);
     var array2 = array.Set(0, "foo");
     Assert.AreEqual("foo", array2[0]);
 }