コード例 #1
0
    public void AddFailDuplicate()
    {
        var dictionary = new DictionaryNoAlloc <string, int>(10);

        dictionary.Add("MyValue", 10);
        Assert.Throws <ArgumentException>(() => dictionary.Add("MyValue", 10));
    }
コード例 #2
0
    public void AddOverRange()
    {
        var dictionary = new DictionaryNoAlloc <string, int>(2);

        dictionary.Add("A", 1);
        dictionary.Add("B", 1);
        Assert.Throws <OverflowException>(() => dictionary.Add("C", 1));
    }
コード例 #3
0
    public void HashClashSevereDuplicated()
    {
        var dictionary = new DictionaryNoAlloc <HashableKey, int>(3);

        dictionary.Add(new HashableKey("A", 1), 10);
        dictionary.Add(new HashableKey("B", 1), 12);
        dictionary.Remove(new HashableKey("A", 1));

        Assert.AreEqual(12, dictionary[new HashableKey("B", 1)]);
    }
コード例 #4
0
    public void Remove()
    {
        var dictionary = new DictionaryNoAlloc <string, int>(10);

        dictionary.Add("MyValue", 10);
        Assert.False(dictionary.Remove("NotUsedValue"));
        Assert.True(dictionary.Remove("MyValue"));
    }
コード例 #5
0
    public void Get()
    {
        var dictionary = new DictionaryNoAlloc <string, int>(10);

        dictionary.Add("MyValue", 10);

        Assert.AreEqual(10, dictionary["MyValue"]);
    }
コード例 #6
0
    public void Clear()
    {
        var dictionary = new DictionaryNoAlloc <int, int>(100);

        for (int i = 0; i < 100; ++i)
        {
            dictionary.Add(i * i, i);
        }

        dictionary.Clear();
        Assert.AreEqual(0, dictionary.Count);
        Assert.Throws <KeyNotFoundException>(() => { int x = dictionary[4]; });
    }
コード例 #7
0
    public void AddMany()
    {
        var dictionary = new DictionaryNoAlloc <int, int>(100);

        for (int i = 0; i < 100; ++i)
        {
            dictionary.Add(i * i, i);
        }

        for (int i = 0; i < 100; ++i)
        {
            Assert.AreEqual(i, dictionary[i * i]);
        }
    }
コード例 #8
0
    public void HashClashSevere()
    {
        var dictionary = new DictionaryNoAlloc <HashableKey, int>(100);

        for (int i = 0; i < 100; ++i)
        {
            dictionary.Add(new HashableKey(i.ToString()), i);
        }

        for (int i = 0; i < 100; ++i)
        {
            var key = new HashableKey(i.ToString());
            Assert.AreEqual(i, dictionary[key]);
        }
    }
コード例 #9
0
    public void Add()
    {
        var dictionary = new DictionaryNoAlloc <string, int>(10);

        dictionary.Add("MyValue", 10);
    }