< Summary

Class:BaseDictionary[TKey,TValue]
Assembly:BaseVariable
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/DataStore/Variables/BaseDictionary.cs
Covered lines:41
Uncovered lines:3
Coverable lines:44
Total lines:104
Line coverage:93.1% (41 of 44)
Covered branches:0
Total branches:0
Covered methods:18
Total methods:20
Method coverage:90% (18 of 20)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BaseDictionary()0%110100%
BaseDictionary(...)0%110100%
BaseDictionary(...)0%330100%
Get()0%110100%
Get(...)0%110100%
TryGetValue(...)0%110100%
Set(...)0%440100%
AddOrSet(...)0%330100%
Add(...)0%220100%
Remove(...)0%330100%
Clear()0%2.152066.67%
ContainsKey(...)0%110100%
ContainsValue(...)0%2100%
Count()0%110100%
GetValues()0%110100%
GetKeys()0%110100%
GetEnumerator()0%110100%
GetEnumerator()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/DataStore/Variables/BaseDictionary.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Linq;
 5
 6public class BaseDictionary<TKey, TValue> : IBaseDictionary<TKey, TValue>, IEnumerable<KeyValuePair<TKey, TValue>>
 7{
 8    public event Action<IEnumerable<KeyValuePair<TKey, TValue>>> OnSet;
 9    public event Action<TKey, TValue> OnAdded;
 10    public event Action<TKey, TValue> OnRemoved;
 11
 12    internal readonly Dictionary<TKey, TValue> dictionary;
 13
 276514    public TValue this[TKey key] { get => dictionary[key]; set => dictionary[key] = value; }
 15
 378116    public BaseDictionary()
 17    {
 378118        dictionary = new Dictionary<TKey, TValue>();
 378119    }
 20
 49121    public BaseDictionary(IEqualityComparer<TKey> comparer)
 22    {
 49123        dictionary = new Dictionary<TKey, TValue>(new Dictionary<TKey, TValue>(), comparer);
 49124    }
 25
 326    public BaseDictionary(IEnumerable<(TKey, TValue)> elements)
 27    {
 328        dictionary = new Dictionary<TKey, TValue>();
 1829        foreach ((TKey key, TValue value) in elements)
 30        {
 631            dictionary.Add(key, value);
 32        }
 333    }
 34
 47435    public IEnumerable<KeyValuePair<TKey, TValue>> Get() => dictionary;
 36
 237    public TValue Get(TKey key) => dictionary[key];
 38
 32139    public bool TryGetValue(TKey key, out TValue value) => dictionary.TryGetValue(key, out value);
 40
 41    public void Set(IEnumerable<(TKey, TValue)> elements)
 42    {
 343        dictionary.Clear();
 2244        foreach ((TKey key, TValue value) in elements)
 45        {
 846            dictionary.Add(key, value);
 47        }
 48
 349        OnSet?.Invoke(dictionary);
 150    }
 51
 52    public void AddOrSet(TKey key, TValue value)
 53    {
 3754        if ( !dictionary.ContainsKey(key))
 3055            dictionary.Add(key, value);
 56        else
 757            dictionary[key] = value;
 58
 3759        OnAdded?.Invoke(key, value);
 2060    }
 61
 62    public void Add(TKey key, TValue value)
 63    {
 314264        dictionary.Add(key, value);
 314265        OnAdded?.Invoke(key, value);
 2166    }
 67
 68    public bool Remove(TKey key)
 69    {
 10670        if (!dictionary.ContainsKey(key))
 3671            return false;
 72
 7073        TValue value = dictionary[key];
 7074        dictionary.Remove(key);
 7075        OnRemoved?.Invoke(key, value);
 7076        return true;
 77    }
 78
 79    public void Clear()
 80    {
 3481        dictionary.Clear();
 3482        OnSet?.Invoke(new Dictionary<TKey, TValue>());
 083    }
 84
 337685    public bool ContainsKey(TKey key) => dictionary.ContainsKey(key);
 086    public bool ContainsValue(TValue value) => dictionary.ContainsValue(value);
 87
 4188    public int Count() => dictionary.Count;
 89
 1090    public List<TValue> GetValues() => dictionary.Values.ToList();
 91
 92    public IEnumerable<TKey> GetKeys() =>
 693        dictionary.Keys;
 94
 95    public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
 96    {
 13297        return dictionary.GetEnumerator();
 98    }
 99
 100    IEnumerator IEnumerable.GetEnumerator()
 101    {
 0102        return dictionary.GetEnumerator();
 103    }
 104}