Skip to content

Commit 1f83b5c

Browse files
committed
tests: Make ToStringTests partial of QuantityTests
1 parent e2033b3 commit 1f83b5c

File tree

2 files changed

+108
-105
lines changed

2 files changed

+108
-105
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
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 System.Globalization;
23+
using UnitsNet.Units;
24+
using Xunit;
25+
26+
namespace UnitsNet.Tests
27+
{
28+
public partial class QuantityTests
29+
{
30+
public class ToString
31+
{
32+
[Fact]
33+
public void ReturnsTheOriginalValueAndUnit()
34+
{
35+
var oldCulture = UnitSystem.DefaultCulture;
36+
try
37+
{
38+
UnitSystem.DefaultCulture = CultureInfo.InvariantCulture;
39+
Assert.Equal("5 kg", Mass.FromKilograms(5).ToString());
40+
Assert.Equal("5,000 g", Mass.FromGrams(5000).ToString());
41+
Assert.Equal("1e-04 long tn", Mass.FromLongTons(1e-4).ToString());
42+
Assert.Equal("3.46e-04 dN/m", ForcePerLength.FromDecinewtonsPerMeter(0.00034567).ToString());
43+
Assert.Equal("0.0069 dB", Level.FromDecibels(0.0069).ToString());
44+
Assert.Equal("0.011 kWh/kg", SpecificEnergy.FromKilowattHoursPerKilogram(0.011).ToString());
45+
// Assert.Equal("0.1 MJ/kg·C", SpecificEntropy.FromMegajoulesPerKilogramDegreeCelsius(0.1).ToString());
46+
Assert.Equal("0.1 MJ/kg.C", SpecificEntropy.FromMegajoulesPerKilogramDegreeCelsius(0.1).ToString());
47+
Assert.Equal("5 cm", Length.FromCentimeters(5).ToString());
48+
}
49+
finally
50+
{
51+
UnitSystem.DefaultCulture = oldCulture;
52+
}
53+
}
54+
55+
[Fact]
56+
public void ConvertsToTheGivenUnit()
57+
{
58+
var oldCulture = UnitSystem.DefaultCulture;
59+
try
60+
{
61+
UnitSystem.DefaultCulture = CultureInfo.InvariantCulture;
62+
Assert.Equal("5,000 g", Mass.FromKilograms(5).ToString(MassUnit.Gram));
63+
Assert.Equal("5 kg", Mass.FromGrams(5000).ToString(MassUnit.Kilogram));
64+
Assert.Equal("0.05 m", Length.FromCentimeters(5).ToString(LengthUnit.Meter));
65+
Assert.Equal("1.97 in", Length.FromCentimeters(5).ToString(LengthUnit.Inch));
66+
}
67+
finally
68+
{
69+
UnitSystem.DefaultCulture = oldCulture;
70+
}
71+
}
72+
73+
[Fact]
74+
public void FormatsNumberUsingGivenCulture()
75+
{
76+
var oldCulture = UnitSystem.DefaultCulture;
77+
try
78+
{
79+
UnitSystem.DefaultCulture = CultureInfo.InvariantCulture;
80+
Assert.Equal("0.05 m", Length.FromCentimeters(5).ToString(LengthUnit.Meter, null));
81+
Assert.Equal("0.05 m", Length.FromCentimeters(5).ToString(LengthUnit.Meter, CultureInfo.InvariantCulture));
82+
Assert.Equal("0,05 m", Length.FromCentimeters(5).ToString(LengthUnit.Meter, new CultureInfo("nb-NO")));
83+
}
84+
finally
85+
{
86+
UnitSystem.DefaultCulture = oldCulture;
87+
}
88+
}
89+
90+
[Fact]
91+
public void FormatsNumberUsingGivenDigitsAfterRadix()
92+
{
93+
var oldCulture = UnitSystem.DefaultCulture;
94+
try
95+
{
96+
UnitSystem.DefaultCulture = CultureInfo.InvariantCulture;
97+
Assert.Equal("0.05 m", Length.FromCentimeters(5).ToString(LengthUnit.Meter, null, 4));
98+
Assert.Equal("1.97 in", Length.FromCentimeters(5).ToString(LengthUnit.Inch, null, 2));
99+
Assert.Equal("1.9685 in", Length.FromCentimeters(5).ToString(LengthUnit.Inch, null, 4));
100+
}
101+
finally
102+
{
103+
UnitSystem.DefaultCulture = oldCulture;
104+
}
105+
}
106+
}
107+
}
108+
}

UnitsNet.Tests/ToStringTests.cs

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)