< Summary

Class:NanoCLang.Entities.SingletonIndex
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Index\SingletonIndex.cs
Covered lines:30
Uncovered lines:6
Coverable lines:36
Total lines:69
Line coverage:83.3% (30 of 36)
Covered branches:10
Total branches:14
Branch coverage:71.4% (10 of 14)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_Offset()100%1100%
CollidesWith(...)83.33%687.5%
SMTPossibleValues(...)100%1100%
Tokens()100%1100%
IncludesOffset(...)100%1100%
SubIndex(...)100%1100%
Add(...)25%460%
Sub(...)100%2100%
Clone()100%1100%
Equals(...)100%1100%
Equals(...)100%2100%
GetHashCode()100%10%
op_Equality(...)100%10%
op_Inequality(...)100%10%

File(s)

C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Index\SingletonIndex.cs

#LineLine coverage
 1using Microsoft.Z3;
 2using System;
 3using System.Collections.Generic;
 4
 5namespace NanoCLang.Entities {
 6    /// <summary>
 7    /// Provides a class for singleton indices.
 8    /// </summary>
 9    public class SingletonIndex : Index, IEquatable<SingletonIndex?> {
 10        /// <summary>
 11        /// Creates a new instance of a singleton index that refers to one single <paramref name="offset"/>.
 12        /// </summary>
 13        /// <param name="offset">Offset that is referred to.</param>
 107014        public SingletonIndex(int offset) {
 53515            Offset = offset;
 53516        }
 17        /// <summary>
 18        /// Offset that is referred to.
 19        /// </summary>
 124720        public int Offset { get; }
 21        /// <inheritdoc/>
 5722        public override bool CollidesWith(int size, Index index, int otherSize) => index switch {
 5723            // Overlapping of half opened intervals [a, b) cap [c, d)
 5724            // ==> a < d && b < c
 5125            SingletonIndex i => Offset < i.Offset + otherSize && i.Offset < Offset + size,
 5726            // Sin cap Seq shall be handled by Seq cap Sin
 627            SequenceIndex i => i.CollidesWith(otherSize, this, size),
 028            _ => base.CollidesWith(size, index, otherSize)
 5729        };
 30        /// <inheritdoc/>
 1031        public override (BoolExpr guard, IntExpr value) SMTPossibleValues(NanoCSMT smt, int size, string prefix) {
 1032            var i = smt.Context.MkIntConst($"{prefix}i");
 1033            return (smt.Context.MkAnd(i >= 0, i < smt.Context.MkInt(size)), (IntExpr)(smt.Context.MkInt(Offset) + i));
 1034        }
 35        /// <inheritdoc/>
 9336        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 9337            yield return Offset.ToString();
 9338        }
 39        /// <inheritdoc/>
 1140        public override bool IncludesOffset(int offset) => offset == Offset;
 41        /// <inheritdoc/>
 7042        public override bool SubIndex(Index other) => other.IncludesOffset(Offset);
 43        /// <inheritdoc/>
 3244        protected override Index Add(Index right) => right switch {
 3245            SingletonIndex i => new SingletonIndex(Offset + i.Offset),
 046            SequenceIndex i => new SequenceIndex(Offset + i.Offset, i.Step),
 047            _ => new ArbitraryIndex()
 3248        };
 49        /// <inheritdoc/>
 1750        protected override Index Sub(Index right) => right switch {
 1551            SingletonIndex i => new SingletonIndex(Offset - i.Offset),
 252            _ => new ArbitraryIndex()
 1753        };
 54        /// <inheritdoc/>
 13955        public override object Clone() => new SingletonIndex(Offset);
 56        #region Equality checks
 57        /// <inheritdoc/>
 37158        public override bool Equals(object? obj) => Equals(obj as SingletonIndex);
 59        /// <inheritdoc/>
 37160        public bool Equals(SingletonIndex? other) => !(other is null) && Offset == other.Offset;
 61        /// <inheritdoc/>
 062        public override int GetHashCode() => HashCode.Combine(Offset);
 63        /// <inheritdoc/>
 064        public static bool operator ==(SingletonIndex? left, SingletonIndex? right) => EqualityComparer<SingletonIndex?>
 65        /// <inheritdoc/>
 066        public static bool operator !=(SingletonIndex? left, SingletonIndex? right) => !(left == right);
 67        #endregion
 68    }
 69}