< Summary

Class:Itinero.Instructions.ToText.ConditionalToText
Assembly:Itinero.Instructions
File(s):/home/runner/work/routing2/routing2/src/Itinero.Instructions/ToText/ConditionalToText.cs
Covered lines:16
Uncovered lines:2
Coverable lines:18
Total lines:43
Line coverage:88.8% (16 of 18)
Covered branches:3
Total branches:6
Branch coverage:50% (3 of 6)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
ToText(...)50%680%

File(s)

/home/runner/work/routing2/routing2/src/Itinero.Instructions/ToText/ConditionalToText.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Runtime.CompilerServices;
 4using Itinero.Instructions.Types;
 5
 6[assembly: InternalsVisibleTo("Itinero.Tests")]
 7[assembly: InternalsVisibleTo("Itinero.Tests.Benchmarks")]
 8[assembly: InternalsVisibleTo("Itinero.Tests.Functional")]
 9
 10namespace Itinero.Instructions.ToText;
 11
 12/// <summary>
 13/// The conditional to text simply contains a list of conditions (predicates) and appropriate 'toText' to generate;
 14/// It basically implements a 'switch case'-instruction
 15/// </summary>
 16internal class ConditionalToText : IInstructionToText
 17{
 18    internal readonly List<(Predicate<BaseInstruction> predicate, IInstructionToText toText)> _options;
 19    private readonly string _context;
 20
 1821    public ConditionalToText(
 1822        List<(Predicate<BaseInstruction>, IInstructionToText)> options,
 1823        string context = "context not set"
 1824    )
 1825    {
 1826        _options = options;
 1827        _context = context;
 1828    }
 29
 30    public string ToText(BaseInstruction instruction)
 3631    {
 21432        foreach (var option in _options)
 7133        {
 7134            if (option.predicate(instruction))
 3635            {
 3636                return option.toText.ToText(instruction);
 37            }
 3538        }
 39
 040        throw new ArgumentException("Fallthrough on the predicates for instruction " + instruction + " during " +
 041                                    _context);
 3642    }
 43}

Methods/Properties

.ctor(...)
ToText(...)