< 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:34
Uncovered lines:5
Coverable lines:39
Total lines:93
Line coverage:87.1% (34 of 39)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
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%2100%
GetValues()0%110100%
GetEnumerator()0%2100%
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
 377712    internal readonly Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>();
 13
 287114    public TValue this[TKey key] { get => dictionary[key]; set => dictionary[key] = value; }
 15
 755016    public BaseDictionary() { }
 17
 218    public BaseDictionary(IEnumerable<(TKey, TValue)> elements)
 19    {
 220        dictionary = new Dictionary<TKey, TValue>();
 1421        foreach ((TKey key, TValue value) in elements)
 22        {
 523            dictionary.Add(key, value);
 24        }
 225    }
 26
 1027    public IEnumerable<KeyValuePair<TKey, TValue>> Get() => dictionary;
 28
 2129    public TValue Get(TKey key) => dictionary[key];
 30
 184131    public bool TryGetValue(TKey key, out TValue value) => dictionary.TryGetValue(key, out value);
 32
 33    public void Set(IEnumerable<(TKey, TValue)> elements)
 34    {
 5735        dictionary.Clear();
 24636        foreach ((TKey key, TValue value) in elements)
 37        {
 6638            dictionary.Add(key, value);
 39        }
 40
 5741        OnSet?.Invoke(dictionary);
 542    }
 43
 44    public void AddOrSet(TKey key, TValue value)
 45    {
 1746        if ( !dictionary.ContainsKey(key))
 547            dictionary.Add(key, value);
 48        else
 1249            dictionary[key] = value;
 50
 1751        OnAdded?.Invoke(key, value);
 352    }
 53
 54    public void Add(TKey key, TValue value)
 55    {
 355456        dictionary.Add(key, value);
 355457        OnAdded?.Invoke(key, value);
 1858    }
 59
 60    public bool Remove(TKey key)
 61    {
 27262        if (!dictionary.ContainsKey(key))
 4363            return false;
 64
 22965        TValue value = dictionary[key];
 22966        dictionary.Remove(key);
 22967        OnRemoved?.Invoke(key, value);
 22968        return true;
 69    }
 70
 71    public void Clear()
 72    {
 89173        dictionary.Clear();
 89174        OnSet?.Invoke(new Dictionary<TKey, TValue>());
 075    }
 76
 406977    public bool ContainsKey(TKey key) => dictionary.ContainsKey(key);
 078    public bool ContainsValue(TValue value) => dictionary.ContainsValue(value);
 79
 080    public int Count() => dictionary.Count;
 81
 5182    public List<TValue> GetValues() => dictionary.Values.ToList();
 83
 84    public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
 85    {
 086        return dictionary.GetEnumerator();
 87    }
 88
 89    IEnumerator IEnumerable.GetEnumerator()
 90    {
 091        return dictionary.GetEnumerator();
 92    }
 93}