Skip to content

Commit 13a1e25

Browse files
committed
Merge pull request #143 from gsokoll/feature/DynamicDensity
Add DynamicViscosity and 3 units
2 parents d97ab51 + dac867a commit 13a1e25

File tree

6 files changed

+830
-0
lines changed

6 files changed

+830
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright © 2007 by Initial Force AS. All rights reserved.
2+
// https://github.com/anjdreas/UnitsNet
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
23+
using System;
24+
using NUnit.Framework;
25+
26+
namespace UnitsNet.Tests.CustomCode
27+
{
28+
public class DynamicViscosityTests : DynamicViscosityTestsBase
29+
{
30+
protected override double CentipoiseInOneNewtonSecondPerMeterSquared => 1e3;
31+
protected override double MillipascalSecondsInOneNewtonSecondPerMeterSquared => 1e3;
32+
protected override double NewtonSecondsPerMeterSquaredInOneNewtonSecondPerMeterSquared => 1;
33+
protected override double PascalSecondsInOneNewtonSecondPerMeterSquared => 1;
34+
protected override double PoiseInOneNewtonSecondPerMeterSquared => 10;
35+
36+
}
37+
}
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
// Copyright © 2007 by Initial Force AS. All rights reserved.
2+
// https://github.com/anjdreas/UnitsNet
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
using System;
23+
using NUnit.Framework;
24+
using UnitsNet.Units;
25+
26+
// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else?
27+
#pragma warning disable 1718
28+
29+
// ReSharper disable once CheckNamespace
30+
namespace UnitsNet.Tests
31+
{
32+
/// <summary>
33+
/// Test of DynamicViscosity.
34+
/// </summary>
35+
[TestFixture]
36+
// ReSharper disable once PartialTypeWithSinglePart
37+
public abstract partial class DynamicViscosityTestsBase
38+
{
39+
protected abstract double CentipoiseInOneNewtonSecondPerMeterSquared { get; }
40+
protected abstract double MillipascalSecondsInOneNewtonSecondPerMeterSquared { get; }
41+
protected abstract double NewtonSecondsPerMeterSquaredInOneNewtonSecondPerMeterSquared { get; }
42+
protected abstract double PascalSecondsInOneNewtonSecondPerMeterSquared { get; }
43+
protected abstract double PoiseInOneNewtonSecondPerMeterSquared { get; }
44+
45+
// ReSharper disable VirtualMemberNeverOverriden.Global
46+
protected virtual double CentipoiseTolerance { get { return 1e-5; } }
47+
protected virtual double MillipascalSecondsTolerance { get { return 1e-5; } }
48+
protected virtual double NewtonSecondsPerMeterSquaredTolerance { get { return 1e-5; } }
49+
protected virtual double PascalSecondsTolerance { get { return 1e-5; } }
50+
protected virtual double PoiseTolerance { get { return 1e-5; } }
51+
// ReSharper restore VirtualMemberNeverOverriden.Global
52+
53+
[Test]
54+
public void NewtonSecondPerMeterSquaredToDynamicViscosityUnits()
55+
{
56+
DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1);
57+
Assert.AreEqual(CentipoiseInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.Centipoise, CentipoiseTolerance);
58+
Assert.AreEqual(MillipascalSecondsInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.MillipascalSeconds, MillipascalSecondsTolerance);
59+
Assert.AreEqual(NewtonSecondsPerMeterSquaredInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance);
60+
Assert.AreEqual(PascalSecondsInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.PascalSeconds, PascalSecondsTolerance);
61+
Assert.AreEqual(PoiseInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.Poise, PoiseTolerance);
62+
}
63+
64+
[Test]
65+
public void FromValueAndUnit()
66+
{
67+
Assert.AreEqual(1, DynamicViscosity.From(1, DynamicViscosityUnit.Centipoise).Centipoise, CentipoiseTolerance);
68+
Assert.AreEqual(1, DynamicViscosity.From(1, DynamicViscosityUnit.MillipascalSecond).MillipascalSeconds, MillipascalSecondsTolerance);
69+
Assert.AreEqual(1, DynamicViscosity.From(1, DynamicViscosityUnit.NewtonSecondPerMeterSquared).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance);
70+
Assert.AreEqual(1, DynamicViscosity.From(1, DynamicViscosityUnit.PascalSecond).PascalSeconds, PascalSecondsTolerance);
71+
Assert.AreEqual(1, DynamicViscosity.From(1, DynamicViscosityUnit.Poise).Poise, PoiseTolerance);
72+
}
73+
74+
[Test]
75+
public void As()
76+
{
77+
var newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1);
78+
Assert.AreEqual(CentipoiseInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.As(DynamicViscosityUnit.Centipoise), CentipoiseTolerance);
79+
Assert.AreEqual(MillipascalSecondsInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.As(DynamicViscosityUnit.MillipascalSecond), MillipascalSecondsTolerance);
80+
Assert.AreEqual(NewtonSecondsPerMeterSquaredInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.As(DynamicViscosityUnit.NewtonSecondPerMeterSquared), NewtonSecondsPerMeterSquaredTolerance);
81+
Assert.AreEqual(PascalSecondsInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.As(DynamicViscosityUnit.PascalSecond), PascalSecondsTolerance);
82+
Assert.AreEqual(PoiseInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.As(DynamicViscosityUnit.Poise), PoiseTolerance);
83+
}
84+
85+
[Test]
86+
public void ConversionRoundTrip()
87+
{
88+
DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1);
89+
Assert.AreEqual(1, DynamicViscosity.FromCentipoise(newtonsecondpermetersquared.Centipoise).NewtonSecondsPerMeterSquared, CentipoiseTolerance);
90+
Assert.AreEqual(1, DynamicViscosity.FromMillipascalSeconds(newtonsecondpermetersquared.MillipascalSeconds).NewtonSecondsPerMeterSquared, MillipascalSecondsTolerance);
91+
Assert.AreEqual(1, DynamicViscosity.FromNewtonSecondsPerMeterSquared(newtonsecondpermetersquared.NewtonSecondsPerMeterSquared).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance);
92+
Assert.AreEqual(1, DynamicViscosity.FromPascalSeconds(newtonsecondpermetersquared.PascalSeconds).NewtonSecondsPerMeterSquared, PascalSecondsTolerance);
93+
Assert.AreEqual(1, DynamicViscosity.FromPoise(newtonsecondpermetersquared.Poise).NewtonSecondsPerMeterSquared, PoiseTolerance);
94+
}
95+
96+
[Test]
97+
public void ArithmeticOperators()
98+
{
99+
DynamicViscosity v = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1);
100+
Assert.AreEqual(-1, -v.NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance);
101+
Assert.AreEqual(2, (DynamicViscosity.FromNewtonSecondsPerMeterSquared(3)-v).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance);
102+
Assert.AreEqual(2, (v + v).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance);
103+
Assert.AreEqual(10, (v*10).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance);
104+
Assert.AreEqual(10, (10*v).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance);
105+
Assert.AreEqual(2, (DynamicViscosity.FromNewtonSecondsPerMeterSquared(10)/5).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance);
106+
Assert.AreEqual(2, DynamicViscosity.FromNewtonSecondsPerMeterSquared(10)/DynamicViscosity.FromNewtonSecondsPerMeterSquared(5), NewtonSecondsPerMeterSquaredTolerance);
107+
}
108+
109+
[Test]
110+
public void ComparisonOperators()
111+
{
112+
DynamicViscosity oneNewtonSecondPerMeterSquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1);
113+
DynamicViscosity twoNewtonSecondsPerMeterSquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(2);
114+
115+
Assert.True(oneNewtonSecondPerMeterSquared < twoNewtonSecondsPerMeterSquared);
116+
Assert.True(oneNewtonSecondPerMeterSquared <= twoNewtonSecondsPerMeterSquared);
117+
Assert.True(twoNewtonSecondsPerMeterSquared > oneNewtonSecondPerMeterSquared);
118+
Assert.True(twoNewtonSecondsPerMeterSquared >= oneNewtonSecondPerMeterSquared);
119+
120+
Assert.False(oneNewtonSecondPerMeterSquared > twoNewtonSecondsPerMeterSquared);
121+
Assert.False(oneNewtonSecondPerMeterSquared >= twoNewtonSecondsPerMeterSquared);
122+
Assert.False(twoNewtonSecondsPerMeterSquared < oneNewtonSecondPerMeterSquared);
123+
Assert.False(twoNewtonSecondsPerMeterSquared <= oneNewtonSecondPerMeterSquared);
124+
}
125+
126+
[Test]
127+
public void CompareToIsImplemented()
128+
{
129+
DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1);
130+
Assert.AreEqual(0, newtonsecondpermetersquared.CompareTo(newtonsecondpermetersquared));
131+
Assert.Greater(newtonsecondpermetersquared.CompareTo(DynamicViscosity.Zero), 0);
132+
Assert.Less(DynamicViscosity.Zero.CompareTo(newtonsecondpermetersquared), 0);
133+
}
134+
135+
[Test]
136+
[ExpectedException(typeof(ArgumentException))]
137+
public void CompareToThrowsOnTypeMismatch()
138+
{
139+
DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1);
140+
// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
141+
newtonsecondpermetersquared.CompareTo(new object());
142+
}
143+
144+
[Test]
145+
[ExpectedException(typeof(ArgumentNullException))]
146+
public void CompareToThrowsOnNull()
147+
{
148+
DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1);
149+
// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
150+
newtonsecondpermetersquared.CompareTo(null);
151+
}
152+
153+
154+
[Test]
155+
public void EqualityOperators()
156+
{
157+
DynamicViscosity a = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1);
158+
DynamicViscosity b = DynamicViscosity.FromNewtonSecondsPerMeterSquared(2);
159+
160+
// ReSharper disable EqualExpressionComparison
161+
Assert.True(a == a);
162+
Assert.True(a != b);
163+
164+
Assert.False(a == b);
165+
Assert.False(a != a);
166+
// ReSharper restore EqualExpressionComparison
167+
}
168+
169+
[Test]
170+
public void EqualsIsImplemented()
171+
{
172+
DynamicViscosity v = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1);
173+
Assert.IsTrue(v.Equals(DynamicViscosity.FromNewtonSecondsPerMeterSquared(1)));
174+
Assert.IsFalse(v.Equals(DynamicViscosity.Zero));
175+
}
176+
177+
[Test]
178+
public void EqualsReturnsFalseOnTypeMismatch()
179+
{
180+
DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1);
181+
Assert.IsFalse(newtonsecondpermetersquared.Equals(new object()));
182+
}
183+
184+
[Test]
185+
public void EqualsReturnsFalseOnNull()
186+
{
187+
DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1);
188+
Assert.IsFalse(newtonsecondpermetersquared.Equals(null));
189+
}
190+
}
191+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright © 2007 by Initial Force AS. All rights reserved.
2+
// https://github.com/anjdreas/UnitsNet
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
// ReSharper disable once CheckNamespace
23+
namespace UnitsNet.Units
24+
{
25+
public enum DynamicViscosityUnit
26+
{
27+
Undefined = 0,
28+
Centipoise,
29+
MillipascalSecond,
30+
NewtonSecondPerMeterSquared,
31+
PascalSecond,
32+
Poise,
33+
}
34+
}

0 commit comments

Comments
 (0)