/**
* Copyright (c) David Miller. All rights reserved.
* The use and distribution terms for this software are covered by the
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
* which can be found in the file epl-v10.html at the root of this distribution.
* By using this software in any fashion, you are agreeing to be bound by
* the terms of this license.
* You must not remove this notice, or any other, from this software.
**/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using NUnit.Framework;
using Rhino.Mocks;
using clojure.lang;
using RMExpect = Rhino.Mocks.Expect;
namespace Clojure.Tests.LibTests
{
[TestFixture]
public class PersistentArrayMapTests : AssertionHelper
{
#region C-tor tests
[Test]
public void CreateOnEmptyDictionaryReturnsEmptyMap()
{
Dictionary<int, string> d = new Dictionary<int, string>();
IPersistentMap m = PersistentArrayMap.create(d);
Expect(m.count(), EqualTo(0));
}
[Test]
public void CreateOnDictionaryReturnsMap()
{
Dictionary<int, string> d = new Dictionary<int, string>();
d[1] = "a";
d[2] = "b";
IPersistentMap m = PersistentArrayMap.create(d);
Expect(m.count(), EqualTo(2));
Expect(m.valAt(1), EqualTo("a"));
Expect(m.valAt(2), EqualTo("b"));
Expect(m.containsKey(3), False);
}
// other c-tors are not public.
#endregion
#region Associative tests
[Test]
public void ContainsKeyOnMissingKeyIsFalse()
{
Dictionary<int, string> d = new Dictionary<int, string>();
d[1] = "a";
d[2] = "b";
IPersistentMap m = PersistentArrayMap.create(d);
Expect(m.containsKey(3), False);
}
[Test]
public void ContainsKeyOnExistingKeyIsTrue()
{
Dictionary<int, string> d = new Dictionary<int, string>();
d[1] = "a";
d[2] = "b";
IPersistentMap m = PersistentArrayMap.create(d);
Expect(m.containsKey(1));
Expect(m.containsKey(2));
}
[Test]
public void ContainsKeyNotConfusedByValue()
{
Dictionary<int, string> d = new Dictionary<int, string>();
d[1] = "a";
d[2] = "b";
IPersistentMap m = PersistentArrayMap.create(d);
Expect(m.containsKey("a"), False);
}
[Test]
public void EntryAtReturnsNullOnMissingKey()
{
Dictionary<int, string> d = new Dictionary<int, string>();
d[1] = "a";
d[2] = "b";
IPersistentMap m = PersistentArrayMap.create(d);
Expect(m.entryAt(3), Null);
}
[Test]
public void EntryAtReturnsEntryforKey()
{
Dictionary<int, string> d = new Dictionary<int, string>();
d[1] = "a";
d[2] = "b";
IPersistentMap m = PersistentArrayMap.create(d);
IMapEntry me = m.entryAt(1);
Expect(me.key(), EqualTo(1));
Expect(me.val(), EqualTo("a"));
}
[Test]
public void ValAt1ReturnsNullOnMissingKey()
{
Dictionary<int, string> d = new Dictionary<int, string>();
d[1] = "a";
d[2] = "b";
IPersistentMap m = PersistentArrayMap.create(d);
Expect(m.valAt(3), Null);
}
[Test]
public void ValAt1ReturnsValueforKey()
{
Dictionary<int, string> d = new Dictionary<int, string>();
d[1] = "a";
d[2] = "b";
IPersistentMap m = PersistentArrayMap.create(d);
Expect(m.valAt(1), EqualTo("a"));
}
[Test]
public void ValAt2ReturnsDefaultOnMissingKey()
{
Dictionary<int, string>