Skip to content

Commit 740cb48

Browse files
erioveAndreas Gullberg Larsen
authored andcommitted
Add decimal, int and long overloads (#298)
1 parent be42442 commit 740cb48

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+45732
-4016
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// Copyright(c) 2007 Andreas Gullberg Larsen
2+
// https://github.com/angularsen/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 Xunit;
23+
using UnitsNet.Extensions.NumberToAcceleration;
24+
using UnitsNet.Extensions.NumberToPower;
25+
26+
namespace UnitsNet.Tests
27+
{
28+
public class DecimalOverloadTests
29+
{
30+
[Fact]
31+
public static void CreatingQuantityWithDoubleBackingFieldFromDecimalReturnsCorrectValue()
32+
{
33+
decimal oneMeterPerSecondSquared = 1m;
34+
Acceleration acceleration = Acceleration.FromMeterPerSecondSquared(oneMeterPerSecondSquared);
35+
Assert.Equal(1.0, acceleration.MeterPerSecondSquared);
36+
}
37+
38+
[Fact]
39+
public static void CreatingQuantityWithDoubleBackingFieldFromNullableDecimalReturnsCorrectValue()
40+
{
41+
decimal? oneMeterPerSecondSquared = 1m;
42+
Acceleration? acceleration = Acceleration.FromMeterPerSecondSquared(oneMeterPerSecondSquared);
43+
Assert.NotNull(acceleration);
44+
Assert.Equal(1.0, acceleration.Value.MeterPerSecondSquared);
45+
}
46+
47+
[Fact]
48+
public static void CreatingQuantityWithDoubleBackingFieldFromNullableDecimalReturnsNullWhenGivenNull()
49+
{
50+
decimal? nullDecimal = null;
51+
Acceleration? acceleration = Acceleration.FromMeterPerSecondSquared(nullDecimal);
52+
Assert.Null(acceleration);
53+
}
54+
55+
[Fact]
56+
public static void CreatingQuantityWithDoubleBackingFieldFromDecimalWithExtensionMethodReturnsCorrectValue()
57+
{
58+
decimal oneMeterPerSecondSquared = 1m;
59+
Acceleration acceleration = oneMeterPerSecondSquared.MeterPerSecondSquared();
60+
Assert.Equal(1.0, acceleration.MeterPerSecondSquared);
61+
}
62+
63+
[Fact]
64+
public static void CreatingQuantityWithDoubleBackingFieldFromNullableDecimalWithExtensionMethodReturnsCorrectValue()
65+
{
66+
decimal? oneMeterPerSecondSquared = 1m;
67+
Acceleration? acceleration = oneMeterPerSecondSquared.MeterPerSecondSquared();
68+
Assert.NotNull(acceleration);
69+
Assert.Equal(1.0, acceleration.Value.MeterPerSecondSquared);
70+
}
71+
72+
[Fact]
73+
public static void CreatingQuantityWithDoubleBackingFieldFromNullableDecimalWithExtensionMethodReturnsNullWhenGivenNull()
74+
{
75+
decimal? nullDecimal = null;
76+
Acceleration? acceleration = nullDecimal.MeterPerSecondSquared();
77+
Assert.Null(acceleration);
78+
}
79+
80+
[Fact]
81+
public static void CreatingQuantityWithDecimalBackingFieldFromDecimalReturnsCorrectValue()
82+
{
83+
decimal oneWatt = 1m;
84+
Power power = Power.FromWatts(oneWatt);
85+
Assert.Equal(1.0, power.Watts);
86+
}
87+
88+
[Fact]
89+
public static void CreatingQuantityWithDecimalBackingFieldFromNullableDecimalReturnsCorrectValue()
90+
{
91+
decimal? oneWatt = 1m;
92+
Power? power = Power.FromWatts(oneWatt);
93+
Assert.NotNull(power);
94+
Assert.Equal(1.0, power.Value.Watts);
95+
}
96+
97+
[Fact]
98+
public static void CreatingQuantityWithDecimalBackingFieldFromNullableDecimalReturnsNullWhenGivenNull()
99+
{
100+
decimal? nullDecimal = null;
101+
Power? power = Power.FromWatts(nullDecimal);
102+
Assert.Null(power);
103+
}
104+
105+
[Fact]
106+
public static void CreatingQuantityWithDecimalBackingFieldFromDecimalWithExtensionMethodReturnsCorrectValue()
107+
{
108+
decimal oneWatt = 1m;
109+
Power power = oneWatt.Watts();
110+
Assert.Equal(1.0, power.Watts);
111+
}
112+
113+
[Fact]
114+
public static void CreatingQuantityWithDecimalBackingFieldFromNullableDecimalWithExtensionMethodReturnsCorrectValue()
115+
{
116+
decimal? oneWatt = 1m;
117+
Power? power = oneWatt.Watts();
118+
Assert.NotNull(power);
119+
Assert.Equal(1.0, power.Value.Watts);
120+
}
121+
122+
[Fact]
123+
public static void CreatingQuantityWithDecimalBackingFieldFromNullableDecimalWithExtensionMethodReturnsNullWhenGivenNull()
124+
{
125+
decimal? nullDecimal = null;
126+
Power? power = nullDecimal.Watts();
127+
Assert.Null(power);
128+
}
129+
}
130+
}

UnitsNet.Tests/IntOverloadTests.cs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// Copyright(c) 2007 Andreas Gullberg Larsen
2+
// https://github.com/angularsen/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 Xunit;
23+
using UnitsNet.Extensions.NumberToAcceleration;
24+
using UnitsNet.Extensions.NumberToPower;
25+
26+
namespace UnitsNet.Tests
27+
{
28+
public class IntOverloadTests
29+
{
30+
[Fact]
31+
public static void CreatingQuantityWithDoubleBackingFieldFromIntReturnsCorrectValue()
32+
{
33+
int oneMeterPerSecondSquared = 1;
34+
Acceleration acceleration = Acceleration.FromMeterPerSecondSquared(oneMeterPerSecondSquared);
35+
Assert.Equal(1.0, acceleration.MeterPerSecondSquared);
36+
}
37+
38+
[Fact]
39+
public static void CreatingQuantityWithDoubleBackingFieldFromNullableIntReturnsCorrectValue()
40+
{
41+
int? oneMeterPerSecondSquared = 1;
42+
Acceleration? acceleration = Acceleration.FromMeterPerSecondSquared(oneMeterPerSecondSquared);
43+
Assert.NotNull(acceleration);
44+
Assert.Equal(1.0, acceleration.Value.MeterPerSecondSquared);
45+
}
46+
47+
[Fact]
48+
public static void CreatingQuantityWithDoubleBackingFieldFromNullableIntReturnsNullWhenGivenNull()
49+
{
50+
int? nullInt = null;
51+
Acceleration? acceleration = Acceleration.FromMeterPerSecondSquared(nullInt);
52+
Assert.Null(acceleration);
53+
}
54+
55+
[Fact]
56+
public static void CreatingQuantityWithDoubleBackingFieldFromIntWithExtensionMethodReturnsCorrectValue()
57+
{
58+
int oneMeterPerSecondSquared = 1;
59+
Acceleration acceleration = oneMeterPerSecondSquared.MeterPerSecondSquared();
60+
Assert.Equal(1.0, acceleration.MeterPerSecondSquared);
61+
}
62+
63+
[Fact]
64+
public static void CreatingQuantityWithDoubleBackingFieldFromNullableIntWithExtensionMethodReturnsCorrectValue()
65+
{
66+
int? oneMeterPerSecondSquared = 1;
67+
Acceleration? acceleration = oneMeterPerSecondSquared.MeterPerSecondSquared();
68+
Assert.NotNull(acceleration);
69+
Assert.Equal(1.0, acceleration.Value.MeterPerSecondSquared);
70+
}
71+
72+
[Fact]
73+
public static void CreatingQuantityWithDoubleBackingFieldFromNullableIntWithExtensionMethodReturnsNullWhenGivenNull()
74+
{
75+
int? nullInt = null;
76+
Acceleration? acceleration = nullInt.MeterPerSecondSquared();
77+
Assert.Null(acceleration);
78+
}
79+
80+
[Fact]
81+
public static void CreatingQuantityWithIntBackingFieldFromIntReturnsCorrectValue()
82+
{
83+
int oneWatt = 1;
84+
Power power = Power.FromWatts(oneWatt);
85+
Assert.Equal(1.0, power.Watts);
86+
}
87+
88+
[Fact]
89+
public static void CreatingQuantityWithIntBackingFieldFromNullableIntReturnsCorrectValue()
90+
{
91+
int? oneWatt = 1;
92+
Power? power = Power.FromWatts(oneWatt);
93+
Assert.NotNull(power);
94+
Assert.Equal(1.0, power.Value.Watts);
95+
}
96+
97+
[Fact]
98+
public static void CreatingQuantityWithIntBackingFieldFromNullableIntReturnsNullWhenGivenNull()
99+
{
100+
int? nullInt = null;
101+
Power? power = Power.FromWatts(nullInt);
102+
Assert.Null(power);
103+
}
104+
105+
[Fact]
106+
public static void CreatingQuantityWithIntBackingFieldFromIntWithExtensionMethodReturnsCorrectValue()
107+
{
108+
int oneWatt = 1;
109+
Power power = oneWatt.Watts();
110+
Assert.Equal(1.0, power.Watts);
111+
}
112+
113+
[Fact]
114+
public static void CreatingQuantityWithIntBackingFieldFromNullableIntWithExtensionMethodReturnsCorrectValue()
115+
{
116+
int? oneWatt = 1;
117+
Power? power = oneWatt.Watts();
118+
Assert.NotNull(power);
119+
Assert.Equal(1.0, power.Value.Watts);
120+
}
121+
122+
[Fact]
123+
public static void CreatingQuantityWithIntBackingFieldFromNullableIntWithExtensionMethodReturnsNullWhenGivenNull()
124+
{
125+
int? nullInt = null;
126+
Power? power = nullInt.Watts();
127+
Assert.Null(power);
128+
}
129+
}
130+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// Copyright(c) 2007 Andreas Gullberg Larsen
2+
// https://github.com/angularsen/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 Xunit;
23+
using UnitsNet.Extensions.NumberToAcceleration;
24+
using UnitsNet.Extensions.NumberToPower;
25+
26+
namespace UnitsNet.Tests
27+
{
28+
public class LongOverloadTests
29+
{
30+
[Fact]
31+
public static void CreatingQuantityWithDoubleBackingFieldFromLongReturnsCorrectValue()
32+
{
33+
long oneMeterPerSecondSquared = 1;
34+
Acceleration acceleration = Acceleration.FromMeterPerSecondSquared(oneMeterPerSecondSquared);
35+
Assert.Equal(1.0, acceleration.MeterPerSecondSquared);
36+
}
37+
38+
[Fact]
39+
public static void CreatingQuantityWithDoubleBackingFieldFromNullableLongReturnsCorrectValue()
40+
{
41+
long? oneMeterPerSecondSquared = 1;
42+
Acceleration? acceleration = Acceleration.FromMeterPerSecondSquared(oneMeterPerSecondSquared);
43+
Assert.NotNull(acceleration);
44+
Assert.Equal(1.0, acceleration.Value.MeterPerSecondSquared);
45+
}
46+
47+
[Fact]
48+
public static void CreatingQuantityWithDoubleBackingFieldFromNullableLongReturnsNullWhenGivenNull()
49+
{
50+
long? nullLong = null;
51+
Acceleration? acceleration = Acceleration.FromMeterPerSecondSquared(nullLong);
52+
Assert.Null(acceleration);
53+
}
54+
55+
[Fact]
56+
public static void CreatingQuantityWithDoubleBackingFieldFromLongWithExtensionMethodReturnsCorrectValue()
57+
{
58+
long oneMeterPerSecondSquared = 1;
59+
Acceleration acceleration = oneMeterPerSecondSquared.MeterPerSecondSquared();
60+
Assert.Equal(1.0, acceleration.MeterPerSecondSquared);
61+
}
62+
63+
[Fact]
64+
public static void CreatingQuantityWithDoubleBackingFieldFromNullableLongWithExtensionMethodReturnsCorrectValue()
65+
{
66+
long? oneMeterPerSecondSquared = 1;
67+
Acceleration? acceleration = oneMeterPerSecondSquared.MeterPerSecondSquared();
68+
Assert.NotNull(acceleration);
69+
Assert.Equal(1.0, acceleration.Value.MeterPerSecondSquared);
70+
}
71+
72+
[Fact]
73+
public static void CreatingQuantityWithDoubleBackingFieldFromNullableLongWithExtensionMethodReturnsNullWhenGivenNull()
74+
{
75+
long? nullLong = null;
76+
Acceleration? acceleration = nullLong.MeterPerSecondSquared();
77+
Assert.Null(acceleration);
78+
}
79+
80+
[Fact]
81+
public static void CreatingQuantityWithLongBackingFieldFromLongReturnsCorrectValue()
82+
{
83+
long oneWatt = 1;
84+
Power power = Power.FromWatts(oneWatt);
85+
Assert.Equal(1.0, power.Watts);
86+
}
87+
88+
[Fact]
89+
public static void CreatingQuantityWithLongBackingFieldFromNullableLongReturnsCorrectValue()
90+
{
91+
long? oneWatt = 1;
92+
Power? power = Power.FromWatts(oneWatt);
93+
Assert.NotNull(power);
94+
Assert.Equal(1.0, power.Value.Watts);
95+
}
96+
97+
[Fact]
98+
public static void CreatingQuantityWithLongBackingFieldFromNullableLongReturnsNullWhenGivenNull()
99+
{
100+
long? nullLong = null;
101+
Power? power = Power.FromWatts(nullLong);
102+
Assert.Null(power);
103+
}
104+
105+
[Fact]
106+
public static void CreatingQuantityWithLongBackingFieldFromLongWithExtensionMethodReturnsCorrectValue()
107+
{
108+
long oneWatt = 1;
109+
Power power = oneWatt.Watts();
110+
Assert.Equal(1.0, power.Watts);
111+
}
112+
113+
[Fact]
114+
public static void CreatingQuantityWithLongBackingFieldFromNullableLongWithExtensionMethodReturnsCorrectValue()
115+
{
116+
long? oneWatt = 1;
117+
Power? power = oneWatt.Watts();
118+
Assert.NotNull(power);
119+
Assert.Equal(1.0, power.Value.Watts);
120+
}
121+
122+
[Fact]
123+
public static void CreatingQuantityWithLongBackingFieldFromNullableLongWithExtensionMethodReturnsNullWhenGivenNull()
124+
{
125+
long? nullLong = null;
126+
Power? power = nullLong.Watts();
127+
Assert.Null(power);
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)