< Summary

Class:NanoCLang.Entities.SequenceIndex
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\Entities\Index\SequenceIndex.cs
Covered lines:39
Uncovered lines:10
Coverable lines:49
Total lines:89
Line coverage:79.5% (39 of 49)
Covered branches:24
Total branches:32
Branch coverage:75% (24 of 32)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)50%2100%
get_Offset()100%1100%
get_Step()100%1100%
CollidesWith(...)100%4100%
SMTPossibleValues(...)100%1100%
Tokens()50%4100%
SubIndex(...)75%866.66%
IncludesOffset(...)100%2100%
Add(...)75%480%
Sub(...)0%20%
GCD(...)100%2100%
Clone()100%1100%
Equals(...)100%1100%
Equals(...)100%4100%
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\SequenceIndex.cs

#LineLine coverage
 1using Microsoft.Z3;
 2using System;
 3using System.Collections.Generic;
 4
 5namespace NanoCLang.Entities {
 6    /// <summary>
 7    /// Provides a class for sequence indices.
 8    /// </summary>
 9    public class SequenceIndex : Index, IEquatable<SequenceIndex?> {
 10        /// <summary>
 11        /// Creates a new instance of a sequence index that refers to a sequence of offsets starting from <paramref name
 12        /// </summary>
 13        /// <param name="offset">Start offset of the sequence.</param>
 14        /// <param name="step">Increments between the sequence offsets.</param>
 111615        public SequenceIndex(int offset, int step) {
 55816            Offset = offset;
 55817            Step = step <= 0 ? throw new ArgumentException("Step must be non-negative!") : step;
 55818        }
 19        /// <summary>
 20        /// Start offset of the sequence.
 21        /// </summary>
 105722        public int Offset { get; }
 23        /// <summary>
 24        /// Increments between the sequence offsets.
 25        /// </summary>
 96426        public int Step { get; }
 27        /// <inheritdoc/>
 2428        public override bool CollidesWith(int size, Index index, int otherSize) => index switch {
 2429            // Handling Seq cap Sin, also redirected from Sin cap Seq
 1230            SingletonIndex i => i.Offset + otherSize > Offset && base.CollidesWith(size, index, otherSize), // No overla
 1231            _ => base.CollidesWith(size, index, otherSize)
 2432        };
 33        /// <inheritdoc/>
 3434        public override (BoolExpr guard, IntExpr value) SMTPossibleValues(NanoCSMT smt, int size, string prefix) {
 3435            var x = smt.Context.MkIntConst($"{prefix}x");
 3436            var i = smt.Context.MkIntConst($"{prefix}i");
 3437            return (smt.Context.MkAnd(i >= 0, i < smt.Context.MkInt(size), x >= 0), (IntExpr)(smt.Context.MkInt(Offset) 
 3438        }
 39        /// <inheritdoc/>
 22040        public override IEnumerable<StringFormatterToken> Tokens(NanoCSourceFormat args) {
 22041            yield return Offset.ToString();
 22042            if (args.SpaceBetweenIndexOffsetAndPlus) yield return " ";
 22043            yield return "+";
 22044            if (args.SpaceBetweenIndexPlusAndStep) yield return " ";
 22045            yield return Step.ToString();
 22046        }
 47        /// <inheritdoc/>
 2348        public override bool SubIndex(Index other) => other switch {
 949            ArbitraryIndex _ => true,
 050            SingletonIndex _ => false,
 1451            SequenceIndex i => i.IncludesOffset(Offset) && (Step % i.Step == 0),
 052            _ => throw new IllFormedException(this, $"Cannot check for subindex with index of type {other.GetType().Name
 2353        };
 54        /// <inheritdoc/>
 4755        public override bool IncludesOffset(int offset) => (offset >= Offset) && ((offset - Offset) % Step == 0);
 56        /// <inheritdoc/>
 1157        protected override Index Add(Index right) => right switch {
 758            SingletonIndex i => new SequenceIndex(Offset + i.Offset, Step),
 459            SequenceIndex i => new SequenceIndex(Offset + i.Offset, GCD(Step, i.Step)),
 060            _ => new ArbitraryIndex()
 1161        };
 62        /// <inheritdoc/>
 063        protected override Index Sub(Index right) => right switch {
 064            SingletonIndex i => new SequenceIndex(Offset - i.Offset, Step),
 065            _ => new ArbitraryIndex()
 066        };
 67        /// <summary>
 68        /// Greatest Common Denominator using Euclidian Algorithm.
 69        /// </summary>
 470        private static int GCD(int a, int b) {
 1271            while (b != 0) b = a % (a = b);
 472            return a;
 473        }
 74        /// <inheritdoc/>
 23775        public override object Clone() => new SequenceIndex(Offset, Step);
 76        #region Equality checks
 77        /// <inheritdoc/>
 24578        public override bool Equals(object? obj) => Equals(obj as SequenceIndex);
 79        /// <inheritdoc/>
 24580        public bool Equals(SequenceIndex? other) => !(other is null) && Offset == other.Offset && Step == other.Step;
 81        /// <inheritdoc/>
 082        public override int GetHashCode() => HashCode.Combine(Offset, Step);
 83        /// <inheritdoc/>
 084        public static bool operator ==(SequenceIndex? left, SequenceIndex? right) => EqualityComparer<SequenceIndex?>.De
 85        /// <inheritdoc/>
 086        public static bool operator !=(SequenceIndex? left, SequenceIndex? right) => !(left == right);
 87        #endregion
 88    }
 89}