Link Search Menu Expand Document

Dictionary Assertions

An assertion tool to verify dictionaries.

  • GdUnitDictionaryAssert

    Function Description
    is_null Verifies that the current value is null.
    is_not_null Verifies that the current value is not null.
    is_equal Verifies that the current dictionary is equal to the given one, ignoring order.
    is_not_equal Verifies that the current dictionary is not equal to the given one, ignoring order.
    is_empty Verifies that the current dictionary is empty, it has a size of 0.
    is_not_empty Verifies that the current dictionary is not empty, it has a size of minimum 1.
    has_size Verifies that the current dictionary has a size of given value.
    contains_keys Verifies that the current dictionary contains the given keys.
    contains_not_keys Verifies that the current dictionary not contains the given keys.
    contains_key_value Verifies that the current dictionary contains the given key and value.
  • IDictionaryAssert

    Function Description
    IsNull Verifies that the current value is null.
    IsNotNull Verifies that the current value is not null.
    IsEqual Verifies that the current dictionary is equal to the given one, ignoring order.
    IsNotEqual Verifies that the current dictionary is not equal to the given one, ignoring order.
    IsEmpty Verifies that the current dictionary is empty, it has a size of 0.
    IsNotEmpty Verifies that the current dictionary is not empty, it has a size of minimum 1.
    HasSize Verifies that the current dictionary has a size of given value.
    ContainsKeys Verifies that the current dictionary contains the given keys.
    NotContainsKeys Verifies that the current dictionary not contains the given keys.
    ContainsKeyValue Verifies that the current dictionary contains the given key and value.

Dictionary Assert Examples

is_null

Verifies that the current value is null.

  •     func assert_dict(<current>).is_null() -> GdUnitDictionaryAssert
    
        # this assertion succeeds
        assert_dict(null).is_null()
    
        # should fail because the dictionary is not null
        assert_dict({}).is_null()
    
  •     public static IDictionaryAssert AssertThat(current).IsNull();
        public static IDictionaryAssert AssertThat<K, V>(current).IsNull();
    
        // this assertion succeeds
        AssertThat(null).IsNull();
    
        // should fail because it not null
        AssertThat(new Hashtable()).IsNull();
    

is_not_null

Verifies that the current value is not null.

  •     func assert_dict(<current>).is_not_null() -> GdUnitDictionaryAssert
    
        # this assertion succeeds
        assert_dict({}).is_not_null()
    
        # should fail because the dictionary is null
        assert_dict(null).is_not_null()
    
  •     public static IDictionaryAssert AssertThat(current).IsNotNull();
        public static IDictionaryAssert AssertThat<K, V>(current).IsNotNull();
    
        // this assertion succeeds
        AssertThat(new Hashtable()).IsNotNull();
    
        // should fail because the current value is null
        AssertThat(null).IsNotNull();
    

is_equal

Verifies that the current dictionary is equal to the given one, ignoring order.

  •     func assert_dict(<current>).is_equal(<expected>) -> GdUnitDictionaryAssert:
    
        # this assertion succeeds
        assert_dict({}).is_equal({})
        assert_dict({1:1}).is_equal({1:1})
        assert_dict({1:1, "key_a": "value_a"}).is_equal({1:1, "key_a": "value_a" })
        # different order is also equals
        assert_dict({"key_a": "value_a", 1:1}).is_equal({1:1, "key_a": "value_a" })
    
        # should fail
        assert_dict({}).is_equal({1:1})
        assert_dict({1:1}).is_equal({1:2})
        assert_dict({1:1, "key_a": "value_a"}).is_equal({1:1, "key_b": "value_b"})
    
  •     public static IDictionaryAssert AssertThat(current).IsEqual();
        public static IDictionaryAssert AssertThat<K, V>(current).IsEqual();
    
        // this assertion succeeds
        AssertThat(new Hashtable()).IsEqual(new Hashtable());
    
        // should fail because is not equal
        AssertThat(new Hashtable()).IsEqual(new Hashtable() { { 1, 1 } });
    

is_not_equal

Verifies that the current dictionary is not equal to the given one, ignoring order.

  •     func assert_dict(<current>).is_not_equal(<expected>) -> GdUnitDictionaryAssert:
    
        # this assertion succeeds
        assert_dict(null).is_not_equal({})
        assert_dict({}).is_not_equal(null)
        assert_dict({}).is_not_equal({1:1})
        assert_dict({1:1}).is_not_equal({})
        assert_dict({1:1}).is_not_equal({1:2})
        assert_dict({2:1}).is_not_equal({1:1})
        assert_dict({1:1}).is_not_equal({1:1, "key_a": "value_a"})
        assert_dict({1:1, "key_a": "value_a"}).is_not_equal({1:1})
        assert_dict({1:1, "key_a": "value_a"}).is_not_equal({1:1,"key_b": "value_b"})
    
        # should fail
        assert_dict({}).is_not_equal({})
        assert_dict({1:1}).is_not_equal({1:1})
        assert_dict({1:1, "key_a": "value_a"}).is_not_equal({1:1, "key_a": "value_a"})
        assert_dict({"key_a": "value_a", 1:1}).is_not_equal({1:1, "key_a": "value_a"})
    
  •     public static IDictionaryAssert AssertThat(current).IsNotEqual();
        public static IDictionaryAssert AssertThat<K, V>(current).IsNotEqual();
    
        // this assertion succeeds
        AssertThat(new Hashtable()).IsNotEqual(new Hashtable() { { 1, 1 } });
    
        // should fail because it is equal
        AssertThat(new Hashtable()).IsNotEqual(new Hashtable());
    

is_empty

Verifies that the current dictionary is empty, it has a size of 0.

  •     func assert_dict(<current>).is_empty() -> GdUnitDictionaryAssert:
    
        # this assertion succeeds
        assert_dict({}).is_empty()
    
        # should fail
        assert_dict(null).is_empty()
        assert_dict({1:1}).is_empty()
    
  •     public static IDictionaryAssert AssertThat(current).IsEmpty();
        public static IDictionaryAssert AssertThat<K, V>(current).IsEmpty();
    
        // this assertion succeeds
        AssertThat(new Hashtable()).IsEmpty();
    
        // should fail because it is NOT empty
        AssertThat(new Hashtable() { { 1, 1 } }).IsEmpty();
    

is_not_empty

Verifies that the current dictionary is not empty, it has a size of minimum 1.

  •     func assert_dict(<current>).is_not_empty() -> GdUnitDictionaryAssert:
    
        # this assertion succeeds
        assert_dict({1:1}).is_not_empty()
        assert_dict({1:1, "key_a": "value_a"}).is_not_empty()
    
        # should fail
        assert_dict(null).is_not_empty()
        assert_dict({}).is_not_empty()
    
  •     public static IDictionaryAssert AssertThat(current).IsNotEmpty();
        public static IDictionaryAssert AssertThat<K, V>(current).IsNotEmpty();
    
        // this assertion succeeds
        AssertThat(new Hashtable() { { 1, 1 } }).IsNotEmpty();
    
        // should fail because it is empty
        AssertThat(new Hashtable()).IsNotEmpty();
    

has_size

Verifies that the current dictionary has a size of given value.

  •     func assert_dict(<current>).has_size(<expected>) -> GdUnitDictionaryAssert:
    
        # this assertion succeeds
        assert_dict({}).has_size(0)
        assert_dict({1:1, 2:1, 3:1}).has_size(3)
    
        # should fail
        assert_dict(null).has_size(0)
        assert_dict({}).has_size(1)
        assert_dict({1:1, 2:1, 3:1}).has_size(4)
    
  •     public static IDictionaryAssert AssertThat(current).HasSize(<count>);
        public static IDictionaryAssert AssertThat<K, V>(current).HasSize(<count>);
    
        // this assertion succeeds
        AssertThat(new Hashtable() { { 1, 1 } }).HasSize(1);
    
        // should fail because it is empty
        AssertThat(new Hashtable()).HasSize(1);
    

contains_keys

Verifies that the current dictionary contains the given key(s).

  •     func assert_dict(<current>).contains_keys(<expected>: Array) -> GdUnitDictionaryAssert:
    
        # this assertion succeeds
        assert_dict({1:1, 2:2, 3:3}).contains_keys([2])
        assert_dict({1:1, 2:2, "key_a": "value_a"}).contains_keys([2, "key_a"])
    
        # should fail
        assert_dict({1:1, 3:3}).contains_keys([2]) # key 2 is missing
        assert_dict({1:1, 3:3}).contains_keys([1, 4]) # key 4 is missing
    
  •     public static IDictionaryAssert AssertThat(current).ContainsKeys(<keys>);
        public static IDictionaryAssert AssertThat<K, V>(current).ContainsKeys(<keys>);
    
        // this assertion succeeds
        AssertThat(new Hashtable() { { "a", 1 }, { "b", 2} }).ContainsKeys("a", "b");
    
        // should fail because it not contains key "c"
        AssertThat(new Hashtable() { { "a", 1 }, { "b", 2} }).ContainsKeys("a", "c");
    

contains_not_keys

Verifies that the current dictionary not contains the given key(s).

  •     func assert_dict(<current>).contains_not_keys(<expected>: Array) -> GdUnitDictionaryAssert:
    
        # this assertion succeeds
        assert_dict({}).contains_not_keys([2])
        assert_dict({1:1, 3:3}).contains_not_keys([2])
        assert_dict({1:1, 3:3}).contains_not_keys([2, 4])
    
        # should fail
        assert_dict({1:1, 2:2, 3:3}).contains_not_keys([2, 4]) # but contains 2
        assert_dict({1:1, 2:2, 3:3}.contains_not_keys([1, 2, 3, 4]) # but contains 1, 2, 3
    
  •     public static IDictionaryAssert AssertThat(current).NotContainsKeys(<keys>);
        public static IDictionaryAssert AssertThat<K, V>(current).NotContainsKeys(<keys>);
    
        // this assertion succeeds
        AssertThat(new Hashtable() { { "a", 1 }, { "b", 2} }).ContainsKeys("c", "d");
    
        // should fail because it contains key "b"
        AssertThat(new Hashtable() { { "a", 1 }, { "b", 2} }).NotContainsKeys("b", "c");
    

contains_key_value

Verifies that the current dictionary contains the given key and value.

  •     func contains_key_value(<key>, <value>) -> GdUnitDictionaryAssert:
    
        # this assertion succeeds
        assert_dict({1:1}).contains_key_value(1, 1)
        assert_dict({1:1, 2:2, 3:3}).contains_key_value(3, 3).contains_key_value(1, 1)
    
        # should fail
        assert_dict({1:1}.contains_key_value(1, 2) # contains key '1' but with value '2'
    
  •     public static IDictionaryAssert AssertThat(current).ContainsKeyValue(<keys>);
        public static IDictionaryAssert AssertThat<K, V>(current).ContainsKeyValue(<keys>);
    
        // this assertion succeeds
        AssertThat(new Hashtable() { { "a", 1 }, { "b", 2} }).ContainsKeyValue("a", "1");
    
        // should fail because it NOT contains key and value "a:2"
        AssertThat(new Hashtable() { { "a", 1 }, { "b", 2} }).ContainsKeyValue("a", "2");
    

Copyright © 2021-2022 Mike Schulze. Distributed by an MIT license.