1. alexdavies74
  2. DataStoreChallenge

Commits

alexdavies74  committed b3b9234

Removal of items

  • Participants
  • Parent commits 93d3a0b
  • Branches default

Comments (0)

Files changed (2)

File DataStoreChallenge/DataStore.cs

View file
  • Ignore whitespace
 {
     class DataStore
     {
+        /// <summary>
+        /// The data store is implemented using an immutable map. This allows fast adding and reading of values (log n)
+        /// but also allows us to instantaneously snapshot the contents of the map at any time, which is useful for the transactions.
+        /// </summary>
         private FSharpMap<string, string> m_Data = new FSharpMap<string, string>(Enumerable.Empty<Tuple<string, string>>());
 
         public void Set(string key, string value)
             FSharpOption<string> maybeValue = m_Data.TryFind(key);
             return maybeValue == FSharpOption<string>.None ? null : maybeValue.Value;
         }
+
+        public void UnSet(string key)
+        {
+            m_Data = m_Data.Remove(key);
+        }
     }
 }

File DataStoreChallenge/Tests/DataStoreTests.cs

View file
  • Ignore whitespace
             m_DataStore.Set("hello", "world");
             Assert.That(m_DataStore.Get("hello"), Is.EqualTo("world"));
         }
+
+        [Test]
+        public void NullIfNotAdded()
+        {
+            Assert.That(m_DataStore.Get("hello"), Is.Null);
+        }
+
+        [Test]
+        public void Remove()
+        {
+            m_DataStore.Set("hello", "world");
+            m_DataStore.UnSet("hello");
+            Assert.That(m_DataStore.Get("hello"), Is.Null);
+        }
     }
 }