< Summary

Information
Class: MyNet.Primitives.Conversion.TemperatureConverter
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Conversion/TemperatureConverter.cs
Tag: 323_28699572109
Line coverage
87%
Covered lines: 14
Uncovered lines: 2
Coverable lines: 16
Total lines: 38
Line coverage: 87.5%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Convert(...)100%11100%
ToCelsius(...)75%4485.71%
FromCelsius(...)75%4485.71%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Conversion/TemperatureConverter.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="TemperatureConverter.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8
 9namespace MyNet.Primitives.Conversion;
 10
 11/// <summary>
 12/// Provides conversion between Celsius, Fahrenheit and Kelvin.
 13/// </summary>
 14public sealed class TemperatureConverter : IUnitConverter<TemperatureUnit>
 15{
 16    public double Convert(double value, TemperatureUnit from, TemperatureUnit to)
 17    {
 2118        var celsius = ToCelsius(value, from);
 2119        return FromCelsius(celsius, to);
 20    }
 21
 2122    private static double ToCelsius(double value, TemperatureUnit unit) => unit switch
 2123    {
 1224        TemperatureUnit.Celsius => value,
 625        TemperatureUnit.Fahrenheit => (value - 32d) * 5d / 9d,
 326        TemperatureUnit.Kelvin => value - 273.15d,
 027        _ => throw new ArgumentOutOfRangeException(nameof(unit), unit, "Unsupported temperature unit.")
 2128    };
 29
 2130    private static double FromCelsius(double value, TemperatureUnit unit) => unit switch
 2131    {
 632        TemperatureUnit.Celsius => value,
 933        TemperatureUnit.Fahrenheit => (value * 9d / 5d) + 32d,
 634        TemperatureUnit.Kelvin => value + 273.15d,
 035        _ => throw new ArgumentOutOfRangeException(nameof(unit), unit, "Unsupported temperature unit.")
 2136    };
 37}
 38