Skip to content

Prune generated tests #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions UnitsNet.Tests/BaseDimensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,54 @@ namespace UnitsNet.Tests
{
public class BaseDimensionsTests
{
[Fact]
public void ConstructorImplementedCorrectly()
{
var baseDimensions = new BaseDimensions(1, 2, 3, 4, 5, 6, 7);

Assert.True(baseDimensions.Length == 1);
Assert.True(baseDimensions.Mass == 2);
Assert.True(baseDimensions.Time == 3);
Assert.True(baseDimensions.Current == 4);
Assert.True(baseDimensions.Temperature == 5);
Assert.True(baseDimensions.Amount == 6);
Assert.True(baseDimensions.LuminousIntensity == 7);
}

[Theory]
[InlineData(1, 0, 0, 0, 0, 0, 0)]
[InlineData(0, 1, 0, 0, 0, 0, 0)]
[InlineData(0, 0, 1, 0, 0, 0, 0)]
[InlineData(0, 0, 0, 1, 0, 0, 0)]
[InlineData(0, 0, 0, 0, 1, 0, 0)]
[InlineData(0, 0, 0, 0, 0, 1, 0)]
[InlineData(0, 0, 0, 0, 0, 0, 1)]
public void IsBaseImplementedSuccessfully(int length, int mass, int time, int current, int temperature, int amount, int luminousIntensity)
{
var baseDimensions = new BaseDimensions(length, mass, time, current, temperature, amount, luminousIntensity);
var derivedDimensions = new BaseDimensions(length * 2, mass * 2, time * 2, current * 2, temperature * 2, amount * 2, luminousIntensity * 2);

Assert.True(baseDimensions.IsBase());
Assert.False(derivedDimensions.IsBase());
}

[Theory]
[InlineData(2, 0, 0, 0, 0, 0, 0)]
[InlineData(0, 2, 0, 0, 0, 0, 0)]
[InlineData(0, 0, 2, 0, 0, 0, 0)]
[InlineData(0, 0, 0, 2, 0, 0, 0)]
[InlineData(0, 0, 0, 0, 2, 0, 0)]
[InlineData(0, 0, 0, 0, 0, 2, 0)]
[InlineData(0, 0, 0, 0, 0, 0, 2)]
public void IsDerivedImplementedSuccessfully(int length, int mass, int time, int current, int temperature, int amount, int luminousIntensity)
{
var baseDimensions = new BaseDimensions(length / 2, mass / 2, time / 2, current / 2, temperature / 2, amount / 2, luminousIntensity / 2);
var derivedDimensions = new BaseDimensions(length, mass, time, current, temperature, amount, luminousIntensity);

Assert.False(baseDimensions.IsDerived());
Assert.True(derivedDimensions.IsDerived());
}

[Fact]
public void EqualsWorksAsExpected()
{
Expand All @@ -32,6 +80,11 @@ public void EqualityOperatorsWorkAsExpected()

Assert.False(baseDimensions2 == null);
Assert.False(null == baseDimensions2);

BaseDimensions nullBaseDimensions1 = null;
BaseDimensions nullBaseDimensions2 = null;

Assert.True(nullBaseDimensions1 == nullBaseDimensions2);
}

[Fact]
Expand All @@ -48,6 +101,11 @@ public void InequalityOperatorsWorkAsExpected()

Assert.True(baseDimensions2 != null);
Assert.True(null != baseDimensions2);

BaseDimensions nullBaseDimensions1 = null;
BaseDimensions nullBaseDimensions2 = null;

Assert.False(nullBaseDimensions1 != nullBaseDimensions2);
}

[Fact]
Expand Down
148 changes: 148 additions & 0 deletions UnitsNet.Tests/BaseUnitsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
// https://github.com/angularsen/UnitsNet
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using UnitsNet.Units;
using Xunit;

namespace UnitsNet.Tests
{
public class BaseUnitsTests
{
[Fact]
public void ConstructorSetsUnitsProperly()
{
var baseUnits = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

Assert.Equal(LengthUnit.Meter, baseUnits.Length);
Assert.Equal(MassUnit.Kilogram, baseUnits.Mass);
Assert.Equal(DurationUnit.Second, baseUnits.Time);
Assert.Equal(ElectricCurrentUnit.Ampere, baseUnits.Current);
Assert.Equal(TemperatureUnit.Kelvin, baseUnits.Temperature);
Assert.Equal(AmountOfSubstanceUnit.Mole, baseUnits.Amount);
Assert.Equal(LuminousIntensityUnit.Candela, baseUnits.LuminousIntensity);
}

[Fact]
public void EqualsObjectIsImplementedCorrectly()
{
var baseUnits1 = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

var baseUnits2 = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

var baseUnits3 = new BaseUnits(LengthUnit.Foot, MassUnit.Pound, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.DegreeFahrenheit, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

Assert.True(baseUnits1.Equals((object)baseUnits2));
Assert.False(baseUnits1.Equals((object)baseUnits3));

Assert.False(baseUnits1.Equals("Some object."));
Assert.False(baseUnits1.Equals((IFormatProvider)null));
}

[Fact]
public void EqualsBaseUnitsIsImplementedCorrectly()
{
var baseUnits1 = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

var baseUnits2 = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

var baseUnits3 = new BaseUnits(LengthUnit.Foot, MassUnit.Pound, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.DegreeFahrenheit, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

Assert.True(baseUnits1.Equals(baseUnits2));
Assert.True(baseUnits2.Equals(baseUnits1));

Assert.False(baseUnits1.Equals(baseUnits3));
Assert.False(baseUnits3.Equals(baseUnits1));

Assert.False(baseUnits1.Equals(null));
}

[Fact]
public void EqualityOperatorIsImplementedCorrectly()
{
var baseUnits1 = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

var baseUnits2 = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

var baseUnits3 = new BaseUnits(LengthUnit.Foot, MassUnit.Pound, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.DegreeFahrenheit, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

Assert.True(baseUnits1 == baseUnits2);
Assert.True(baseUnits2 == baseUnits1);

Assert.False(baseUnits1 == baseUnits3);
Assert.False(baseUnits3 == baseUnits1);

Assert.False(baseUnits1 == null);
Assert.False(null == baseUnits1);

BaseUnits nullBaseUnits1 = null;
BaseUnits nullBaseUnits2 = null;

Assert.True(nullBaseUnits1 == nullBaseUnits2);
}

[Fact]
public void InequalityOperatorIsImplementedCorrectly()
{
var baseUnits1 = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

var baseUnits2 = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

var baseUnits3 = new BaseUnits(LengthUnit.Foot, MassUnit.Pound, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.DegreeFahrenheit, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

Assert.False(baseUnits1 != baseUnits2);
Assert.False(baseUnits2 != baseUnits1);

Assert.True(baseUnits1 != baseUnits3);
Assert.True(baseUnits3 != baseUnits1);

Assert.True(baseUnits1 != null);
Assert.True(null != baseUnits1);

BaseUnits nullBaseUnits1 = null;
BaseUnits nullBaseUnits2 = null;

Assert.False(nullBaseUnits1 != nullBaseUnits2);
}

[Fact]
public void ToStringGivesExpectedResult()
{
var baseUnits1 = new BaseUnits(LengthUnit.Meter, MassUnit.Kilogram, DurationUnit.Second,
ElectricCurrentUnit.Ampere, TemperatureUnit.Kelvin, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela);

Assert.Equal("[Length]: m, [Mass]: kg, [Time]: s, [Current]: A, [Temperature]: K, [Amount]: mol, [LuminousIntensity]: cd", baseUnits1.ToString());
}
}
}
4 changes: 4 additions & 0 deletions UnitsNet.Tests/GeneratedCode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.g.cs
!InformationTestsBase.g.cs
!LengthTestsBase.g.cs
!LevelTestsBase.g.cs
Loading