< Summary

Class:BaseDictionary[TKey,TValue]
Assembly:DataStore
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/DataStore/Variables/BaseDictionary.cs
Covered lines:28
Uncovered lines:11
Coverable lines:39
Total lines:93
Line coverage:71.7% (28 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%2100%
Get(...)0%110100%
TryGetValue(...)0%110100%
Set(...)0%440100%
AddOrSet(...)0%12300%
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
 625312    internal readonly Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>();
 13
 374814    public TValue this[TKey key] { get => dictionary[key]; set => dictionary[key] = value; }
 15
 1250216    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
 027    public IEnumerable<KeyValuePair<TKey, TValue>> Get() => dictionary;
 28
 2129    public TValue Get(TKey key) => dictionary[key];
 30
 117931    public bool TryGetValue(TKey key, out TValue value) => dictionary.TryGetValue(key, out value);
 32
 33    public void Set(IEnumerable<(TKey, TValue)> elements)
 34    {
 5935        dictionary.Clear();
 25436        foreach ((TKey key, TValue value) in elements)
 37        {
 6838            dictionary.Add(key, value);
 39        }
 40
 5941        OnSet?.Invoke(dictionary);
 542    }
 43
 44    public void AddOrSet(TKey key, TValue value)
 45    {
 046        if ( !dictionary.ContainsKey(key))
 047            dictionary.Add(key, value);
 48        else
 049            dictionary[key] = value;
 50
 051        OnAdded?.Invoke(key, value);
 052    }
 53
 54    public void Add(TKey key, TValue value)
 55    {
 290956        dictionary.Add(key, value);
 290957        OnAdded?.Invoke(key, value);
 22358    }
 59
 60    public bool Remove(TKey key)
 61    {
 58862        if (!dictionary.ContainsKey(key))
 5163            return false;
 64
 53765        TValue value = dictionary[key];
 53766        dictionary.Remove(key);
 53767        OnRemoved?.Invoke(key, value);
 53768        return true;
 69    }
 70
 71    public void Clear()
 72    {
 27273        dictionary.Clear();
 27274        OnSet?.Invoke(new Dictionary<TKey, TValue>());
 075    }
 76
 289877    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
 7382    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}