Skip to content

Commit 0f674c1

Browse files
committed
Merge pull request #127 from neutmute/feature/add-vitamina
Add VitaminA international unit
2 parents 0f3d871 + 94b1464 commit 0f674c1

File tree

6 files changed

+649
-0
lines changed

6 files changed

+649
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright © 2007 by Initial Force AS. All rights reserved.
2+
// https://github.com/InitialForce/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+
25+
namespace UnitsNet.Tests.CustomCode
26+
{
27+
public class VitaminATests : VitaminATestsBase
28+
{
29+
protected override double InternationalUnitsInOneInternationalUnit { get { return 1; } }
30+
}
31+
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Copyright © 2007 by Initial Force AS. All rights reserved.
2+
// https://github.com/InitialForce/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 VitaminA.
34+
/// </summary>
35+
[TestFixture]
36+
// ReSharper disable once PartialTypeWithSinglePart
37+
public abstract partial class VitaminATestsBase
38+
{
39+
protected abstract double InternationalUnitsInOneInternationalUnit { get; }
40+
41+
// ReSharper disable VirtualMemberNeverOverriden.Global
42+
protected virtual double InternationalUnitsTolerance { get { return 1e-5; } }
43+
// ReSharper restore VirtualMemberNeverOverriden.Global
44+
45+
[Test]
46+
public void InternationalUnitToVitaminAUnits()
47+
{
48+
VitaminA internationalunit = VitaminA.FromInternationalUnits(1);
49+
Assert.AreEqual(InternationalUnitsInOneInternationalUnit, internationalunit.InternationalUnits, InternationalUnitsTolerance);
50+
}
51+
52+
[Test]
53+
public void FromValueAndUnit()
54+
{
55+
Assert.AreEqual(1, VitaminA.From(1, VitaminAUnit.InternationalUnit).InternationalUnits, InternationalUnitsTolerance);
56+
}
57+
58+
[Test]
59+
public void As()
60+
{
61+
var internationalunit = VitaminA.FromInternationalUnits(1);
62+
Assert.AreEqual(InternationalUnitsInOneInternationalUnit, internationalunit.As(VitaminAUnit.InternationalUnit), InternationalUnitsTolerance);
63+
}
64+
65+
[Test]
66+
public void ConversionRoundTrip()
67+
{
68+
VitaminA internationalunit = VitaminA.FromInternationalUnits(1);
69+
Assert.AreEqual(1, VitaminA.FromInternationalUnits(internationalunit.InternationalUnits).InternationalUnits, InternationalUnitsTolerance);
70+
}
71+
72+
[Test]
73+
public void ArithmeticOperators()
74+
{
75+
VitaminA v = VitaminA.FromInternationalUnits(1);
76+
Assert.AreEqual(-1, -v.InternationalUnits, InternationalUnitsTolerance);
77+
Assert.AreEqual(2, (VitaminA.FromInternationalUnits(3)-v).InternationalUnits, InternationalUnitsTolerance);
78+
Assert.AreEqual(2, (v + v).InternationalUnits, InternationalUnitsTolerance);
79+
Assert.AreEqual(10, (v*10).InternationalUnits, InternationalUnitsTolerance);
80+
Assert.AreEqual(10, (10*v).InternationalUnits, InternationalUnitsTolerance);
81+
Assert.AreEqual(2, (VitaminA.FromInternationalUnits(10)/5).InternationalUnits, InternationalUnitsTolerance);
82+
Assert.AreEqual(2, VitaminA.FromInternationalUnits(10)/VitaminA.FromInternationalUnits(5), InternationalUnitsTolerance);
83+
}
84+
85+
[Test]
86+
public void ComparisonOperators()
87+
{
88+
VitaminA oneInternationalUnit = VitaminA.FromInternationalUnits(1);
89+
VitaminA twoInternationalUnits = VitaminA.FromInternationalUnits(2);
90+
91+
Assert.True(oneInternationalUnit < twoInternationalUnits);
92+
Assert.True(oneInternationalUnit <= twoInternationalUnits);
93+
Assert.True(twoInternationalUnits > oneInternationalUnit);
94+
Assert.True(twoInternationalUnits >= oneInternationalUnit);
95+
96+
Assert.False(oneInternationalUnit > twoInternationalUnits);
97+
Assert.False(oneInternationalUnit >= twoInternationalUnits);
98+
Assert.False(twoInternationalUnits < oneInternationalUnit);
99+
Assert.False(twoInternationalUnits <= oneInternationalUnit);
100+
}
101+
102+
[Test]
103+
public void CompareToIsImplemented()
104+
{
105+
VitaminA internationalunit = VitaminA.FromInternationalUnits(1);
106+
Assert.AreEqual(0, internationalunit.CompareTo(internationalunit));
107+
Assert.Greater(internationalunit.CompareTo(VitaminA.Zero), 0);
108+
Assert.Less(VitaminA.Zero.CompareTo(internationalunit), 0);
109+
}
110+
111+
[Test]
112+
[ExpectedException(typeof(ArgumentException))]
113+
public void CompareToThrowsOnTypeMismatch()
114+
{
115+
VitaminA internationalunit = VitaminA.FromInternationalUnits(1);
116+
// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
117+
internationalunit.CompareTo(new object());
118+
}
119+
120+
[Test]
121+
[ExpectedException(typeof(ArgumentNullException))]
122+
public void CompareToThrowsOnNull()
123+
{
124+
VitaminA internationalunit = VitaminA.FromInternationalUnits(1);
125+
// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
126+
internationalunit.CompareTo(null);
127+
}
128+
129+
130+
[Test]
131+
public void EqualityOperators()
132+
{
133+
VitaminA a = VitaminA.FromInternationalUnits(1);
134+
VitaminA b = VitaminA.FromInternationalUnits(2);
135+
136+
// ReSharper disable EqualExpressionComparison
137+
Assert.True(a == a);
138+
Assert.True(a != b);
139+
140+
Assert.False(a == b);
141+
Assert.False(a != a);
142+
// ReSharper restore EqualExpressionComparison
143+
}
144+
145+
[Test]
146+
public void EqualsIsImplemented()
147+
{
148+
VitaminA v = VitaminA.FromInternationalUnits(1);
149+
Assert.IsTrue(v.Equals(VitaminA.FromInternationalUnits(1)));
150+
Assert.IsFalse(v.Equals(VitaminA.Zero));
151+
}
152+
153+
[Test]
154+
public void EqualsReturnsFalseOnTypeMismatch()
155+
{
156+
VitaminA internationalunit = VitaminA.FromInternationalUnits(1);
157+
Assert.IsFalse(internationalunit.Equals(new object()));
158+
}
159+
160+
[Test]
161+
public void EqualsReturnsFalseOnNull()
162+
{
163+
VitaminA internationalunit = VitaminA.FromInternationalUnits(1);
164+
Assert.IsFalse(internationalunit.Equals(null));
165+
}
166+
}
167+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright © 2007 by Initial Force AS. All rights reserved.
2+
// https://github.com/InitialForce/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 VitaminAUnit
26+
{
27+
Undefined = 0,
28+
InternationalUnit,
29+
}
30+
}

0 commit comments

Comments
 (0)