Skip to content
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

Fix a bug in BaseDimensions.IsBaseQuantity() #1430

Merged
Changes from 1 commit
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
Prev Previous commit
* IsBaseDimension unit tests
ygorshkov committed Oct 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 9d20fd8016296bf00aa63a26d84e3c5f0268381b
40 changes: 36 additions & 4 deletions UnitsNet.Tests/BaseDimensionsTests.cs
Original file line number Diff line number Diff line change
@@ -28,17 +28,49 @@ public void ConstructorImplementedCorrectly()
[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 IsBaseQuantityImplementedProperly(int length, int mass, int time, int current, int temperature, int amount, int luminousIntensity)
public void IsBaseQuantity_ForBaseQuantity_ReturnsTrue(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.IsBaseQuantity());
}

[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 IsBaseQuantity_ForDerivedQuantity_ReturnsFalse(int length, int mass, int time, int current, int temperature, int amount, int luminousIntensity)
{
var derivedDimensions = new BaseDimensions(length, mass, time, current, temperature, amount, luminousIntensity);
Assert.False(derivedDimensions.IsBaseQuantity());
}

[Theory]
[InlineData(1, 1, 0, 0, 0, 0, 0)]
[InlineData(0, 2, 1, 0, 0, 0, 0)]
[InlineData(0, 2, 1, 1, 0, 0, 0)]
[InlineData(1, 2, 1, 1, 1, 1, 1)]
[InlineData(0, 0, 1, 2,-2, 0, 0)]
[InlineData(0, 0, 2,-1, 0, 0, 0)]
[InlineData(0, 0, 0,-3, 1, 0, 0)]
[InlineData(0, 0, 0, 0,-4,-4, 0)]
public void IsBaseQuantity_ForMultipleDimensions_ReturnsFalse(int length, int mass, int time, int current, int temperature, int amount, int luminousIntensity)
{
var derivedDimensions = new BaseDimensions(length, mass, time, current, temperature, amount, luminousIntensity);
Assert.False(derivedDimensions.IsBaseQuantity());
}

[Fact]
public void IsBaseQuantityImplementedReallyProperly()
public void IsBaseQuantity_ForDimensionless_ReturnsFalse()
{
Assert.False(BaseDimensions.Dimensionless.IsBaseQuantity());
}

[Fact]
public void IsBaseQuantity_ForAcceleration_ReturnsFalse()
{
Assert.False(Acceleration.BaseDimensions.IsBaseQuantity());
angularsen marked this conversation as resolved.
Show resolved Hide resolved
}