Skip to content

Commit b094d17

Browse files
Added Pressure unit and unit tests.
1 parent 3fa0ba3 commit b094d17

12 files changed

+1729
-0
lines changed

OnixLabs.Units.UnitTests/PressureTests.cs

Lines changed: 686 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2020-2025 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace OnixLabs.Units;
16+
17+
// ReSharper disable MemberCanBePrivate.Global
18+
public readonly partial struct Pressure<T>
19+
{
20+
/// <summary>
21+
/// Computes the sum of the specified <see cref="Pressure{T}"/> values.
22+
/// </summary>
23+
/// <param name="left">The left-hand value to add to.</param>
24+
/// <param name="right">The right-hand value to add.</param>
25+
/// <returns>Returns the sum of the specified <see cref="Pressure{T}"/> values.</returns>
26+
public static Pressure<T> Add(Pressure<T> left, Pressure<T> right) => new(left.QuectoPascals + right.QuectoPascals);
27+
28+
/// <summary>
29+
/// Computes the sum of the specified <see cref="Pressure{T}"/> values.
30+
/// </summary>
31+
/// <param name="left">The left-hand value to add to.</param>
32+
/// <param name="right">The right-hand value to add.</param>
33+
/// <returns>Returns the sum of the specified <see cref="Pressure{T}"/> values.</returns>
34+
public static Pressure<T> operator +(Pressure<T> left, Pressure<T> right) => Add(left, right);
35+
36+
/// <summary>
37+
/// Computes the sum of the current <see cref="Pressure{T}"/> value and the specified other <see cref="Pressure{T}"/> value.
38+
/// </summary>
39+
/// <param name="other">The value to add to the current <see cref="Pressure{T}"/> value.</param>
40+
/// <returns>Returns the sum of the current <see cref="Pressure{T}"/> value and the specified other <see cref="Pressure{T}"/> value.</returns>
41+
public Pressure<T> Add(Pressure<T> other) => Add(this, other);
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2020-2025 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace OnixLabs.Units;
16+
17+
// ReSharper disable MemberCanBePrivate.Global
18+
public readonly partial struct Pressure<T>
19+
{
20+
/// <summary>
21+
/// Computes the quotient of the specified <see cref="Pressure{T}"/> values.
22+
/// </summary>
23+
/// <param name="left">The left-hand value to divide.</param>
24+
/// <param name="right">The right-hand value to divide by.</param>
25+
/// <returns>Returns the quotient of the specified <see cref="Pressure{T}"/> values.</returns>
26+
public static Pressure<T> Divide(Pressure<T> left, Pressure<T> right) => new(left.QuectoPascals / right.QuectoPascals);
27+
28+
/// <summary>
29+
/// Computes the quotient of the specified <see cref="Pressure{T}"/> values.
30+
/// </summary>
31+
/// <param name="left">The left-hand value to divide.</param>
32+
/// <param name="right">The right-hand value to divide by.</param>
33+
/// <returns>Returns the quotient of the specified <see cref="Pressure{T}"/> values.</returns>
34+
public static Pressure<T> operator /(Pressure<T> left, Pressure<T> right) => Divide(left, right);
35+
36+
/// <summary>
37+
/// Computes the quotient of the current <see cref="Pressure{T}"/> value and the specified other <see cref="Pressure{T}"/> value.
38+
/// </summary>
39+
/// <param name="other">The value to divide the current <see cref="Pressure{T}"/> value by.</param>
40+
/// <returns>Returns the quotient of the current <see cref="Pressure{T}"/> value and the specified other <see cref="Pressure{T}"/> value.</returns>
41+
public Pressure<T> Divide(Pressure<T> other) => Divide(this, other);
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2020-2025 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace OnixLabs.Units;
16+
17+
// ReSharper disable MemberCanBePrivate.Global
18+
public readonly partial struct Pressure<T>
19+
{
20+
/// <summary>
21+
/// Computes the product of the specified <see cref="Pressure{T}"/> values.
22+
/// </summary>
23+
/// <param name="left">The left-hand value to multiply.</param>
24+
/// <param name="right">The right-hand value to multiply.</param>
25+
/// <returns>Returns the product of the specified <see cref="Pressure{T}"/> values.</returns>
26+
public static Pressure<T> Multiply(Pressure<T> left, Pressure<T> right) => new(left.QuectoPascals * right.QuectoPascals);
27+
28+
/// <summary>
29+
/// Computes the product of the specified <see cref="Pressure{T}"/> values.
30+
/// </summary>
31+
/// <param name="left">The left-hand value to multiply.</param>
32+
/// <param name="right">The right-hand value to multiply.</param>
33+
/// <returns>Returns the product of the specified <see cref="Pressure{T}"/> values.</returns>
34+
public static Pressure<T> operator *(Pressure<T> left, Pressure<T> right) => Multiply(left, right);
35+
36+
/// <summary>
37+
/// Computes the product of the current <see cref="Pressure{T}"/> value and the specified other <see cref="Pressure{T}"/> value.
38+
/// </summary>
39+
/// <param name="other">The value to multiply with the current <see cref="Pressure{T}"/> value.</param>
40+
/// <returns>Returns the product of the current <see cref="Pressure{T}"/> value and the specified other <see cref="Pressure{T}"/> value.</returns>
41+
public Pressure<T> Multiply(Pressure<T> other) => Multiply(this, other);
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2020-2025 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace OnixLabs.Units;
16+
17+
// ReSharper disable MemberCanBePrivate.Global
18+
public readonly partial struct Pressure<T>
19+
{
20+
/// <summary>
21+
/// Computes the difference between the specified <see cref="Pressure{T}"/> values.
22+
/// </summary>
23+
/// <param name="left">The left-hand value to subtract from.</param>
24+
/// <param name="right">The right-hand value to subtract.</param>
25+
/// <returns>Returns the difference between the specified <see cref="Pressure{T}"/> values.</returns>
26+
public static Pressure<T> Subtract(Pressure<T> left, Pressure<T> right) => new(left.QuectoPascals - right.QuectoPascals);
27+
28+
/// <summary>
29+
/// Computes the difference between the specified <see cref="Pressure{T}"/> values.
30+
/// </summary>
31+
/// <param name="left">The left-hand value to subtract from.</param>
32+
/// <param name="right">The right-hand value to subtract.</param>
33+
/// <returns>Returns the difference between the specified <see cref="Pressure{T}"/> values.</returns>
34+
public static Pressure<T> operator -(Pressure<T> left, Pressure<T> right) => Subtract(left, right);
35+
36+
/// <summary>
37+
/// Computes the difference between the current <see cref="Pressure{T}"/> value and the specified other <see cref="Pressure{T}"/> value.
38+
/// </summary>
39+
/// <param name="other">The value to subtract from the current <see cref="Pressure{T}"/> value.</param>
40+
/// <returns>Returns the difference between the current <see cref="Pressure{T}"/> value and the specified other <see cref="Pressure{T}"/> value.</returns>
41+
public Pressure<T> Subtract(Pressure<T> other) => Subtract(this, other);
42+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright 2020-2025 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using OnixLabs.Core;
16+
17+
namespace OnixLabs.Units;
18+
19+
// ReSharper disable MemberCanBePrivate.Global
20+
public readonly partial struct Pressure<T>
21+
{
22+
/// <summary>
23+
/// Compares two <see cref="Pressure{T}"/> values and returns an integer that indicates
24+
/// whether the left-hand value is less than, equal to, or greater than the right-hand value.
25+
/// </summary>
26+
/// <param name="left">The left-hand value to compare.</param>
27+
/// <param name="right">The right-hand value to compare.</param>
28+
/// <returns>
29+
/// Returns a value that indicates the relative order of the values being compared.
30+
/// The return value is less than zero if <paramref name="left"/> is less than <paramref name="right"/>,
31+
/// zero if <paramref name="left"/> equals <paramref name="right"/>,
32+
/// or greater than zero if <paramref name="left"/> is greater than <paramref name="right"/>.
33+
/// </returns>
34+
public static int Compare(Pressure<T> left, Pressure<T> right) => left.QuectoPascals.CompareTo(right.QuectoPascals);
35+
36+
/// <summary>
37+
/// Compares the current instance with another object of the same type and returns an integer that indicates
38+
/// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
39+
/// other object.
40+
/// </summary>
41+
/// <param name="other">An object to compare with this instance.</param>
42+
/// <returns>
43+
/// Returns a value that indicates the relative order of the values being compared.
44+
/// The return value is less than zero if the current instance is less than <paramref name="other"/>,
45+
/// zero if the current instance equals <paramref name="other"/>,
46+
/// or greater than zero if the current instance is greater than <paramref name="other"/>.
47+
/// </returns>
48+
public int CompareTo(Pressure<T> other) => Compare(this, other);
49+
50+
/// <summary>
51+
/// Compares the current instance with another object of the same type and returns an integer that indicates
52+
/// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
53+
/// other object.
54+
/// </summary>
55+
/// <param name="obj">An object to compare with this instance.</param>
56+
/// <returns>Returns a value that indicates the relative order of the objects being compared.</returns>
57+
// ReSharper disable once HeapView.BoxingAllocation
58+
public int CompareTo(object? obj) => this.CompareToObject(obj);
59+
60+
/// <summary>
61+
/// Determines whether the left-hand value is greater than the right-hand value.
62+
/// </summary>
63+
/// <param name="left">The left-hand value to compare.</param>
64+
/// <param name="right">The right-hand value to compare.</param>
65+
/// <returns>
66+
/// Returns <see langword="true"/> if the left-hand value is greater than the right-hand value;
67+
/// otherwise, <see langword="false"/>.
68+
/// </returns>
69+
public static bool operator >(Pressure<T> left, Pressure<T> right) => Compare(left, right) is 1;
70+
71+
/// <summary>
72+
/// Determines whether the left-hand value is greater than or equal to the right-hand value.
73+
/// </summary>
74+
/// <param name="left">The left-hand value to compare.</param>
75+
/// <param name="right">The right-hand value to compare.</param>
76+
/// <returns>
77+
/// Returns <see langword="true"/> if the left-hand value is greater than or equal to the right-hand value;
78+
/// otherwise, <see langword="false"/>.
79+
/// </returns>
80+
public static bool operator >=(Pressure<T> left, Pressure<T> right) => Compare(left, right) is 1 or 0;
81+
82+
/// <summary>
83+
/// Determines whether the left-hand value is less than the right-hand value.
84+
/// </summary>
85+
/// <param name="left">The left-hand value to compare.</param>
86+
/// <param name="right">The right-hand value to compare.</param>
87+
/// <returns>
88+
/// Returns <see langword="true"/> if the left-hand value is less than the right-hand value;
89+
/// otherwise, <see langword="false"/>.
90+
/// </returns>
91+
public static bool operator <(Pressure<T> left, Pressure<T> right) => Compare(left, right) is -1;
92+
93+
/// <summary>
94+
/// Determines whether the left-hand value is less than or equal to the right-hand value.
95+
/// </summary>
96+
/// <param name="left">The left-hand value to compare.</param>
97+
/// <param name="right">The right-hand value to compare.</param>
98+
/// <returns>
99+
/// Returns <see langword="true"/> if the left-hand value is less than or equal to the right-hand value;
100+
/// otherwise, <see langword="false"/>.
101+
/// </returns>
102+
public static bool operator <=(Pressure<T> left, Pressure<T> right) => Compare(left, right) is -1 or 0;
103+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2020-2025 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace OnixLabs.Units;
16+
17+
public readonly partial struct Pressure<T>
18+
{
19+
/// <summary>
20+
/// Gets a zero <see cref="Pressure{T}"/> value, equal to zero quectopascals.
21+
/// </summary>
22+
public static readonly Pressure<T> Zero = new(T.Zero);
23+
24+
private const string QuectoPascalsSpecifier = "qPa";
25+
private const string RontoPascalsSpecifier = "rPa";
26+
private const string YoctoPascalsSpecifier = "yPa";
27+
private const string ZeptoPascalsSpecifier = "zPa";
28+
private const string AttoPascalsSpecifier = "aPa";
29+
private const string FemtoPascalsSpecifier = "fPa";
30+
private const string PicoPascalsSpecifier = "pPa";
31+
private const string NanoPascalsSpecifier = "nPa";
32+
private const string MicroPascalsSpecifier = "uPa";
33+
private const string MilliPascalsSpecifier = "mPa";
34+
private const string CentiPascalsSpecifier = "cPa";
35+
private const string DeciPascalsSpecifier = "dPa";
36+
private const string PascalsSpecifier = "Pa";
37+
private const string DecaPascalsSpecifier = "daPa";
38+
private const string HectoPascalsSpecifier = "hPa";
39+
private const string KiloPascalsSpecifier = "kPa";
40+
private const string MegaPascalsSpecifier = "MPa";
41+
private const string GigaPascalsSpecifier = "GPa";
42+
private const string TeraPascalsSpecifier = "TPa";
43+
private const string PetaPascalsSpecifier = "PPa";
44+
private const string ExaPascalsSpecifier = "EPa";
45+
private const string ZettaPascalsSpecifier = "ZPa";
46+
private const string YottaPascalsSpecifier = "YPa";
47+
private const string RonnaPascalsSpecifier = "RPa";
48+
private const string QuettaPascalsSpecifier = "QPa";
49+
private const string BarsSpecifier = "bar";
50+
private const string MillibarsSpecifier = "mbar";
51+
private const string AtmospheresSpecifier = "atm";
52+
private const string TechnicalAtmospheresSpecifier = "at";
53+
private const string TorrSpecifier = "Torr";
54+
private const string MillimetersOfMercurySpecifier = "mmHg";
55+
private const string InchesOfMercurySpecifier = "inHg";
56+
private const string PoundsPerSquareInchSpecifier = "psi";
57+
private const string PoundsPerSquareFootSpecifier = "psf";
58+
private const string BaryeSpecifier = "Ba";
59+
private const string MillimetersOfWaterColumnSpecifier = "mmH2O";
60+
private const string InchesOfWaterColumnSpecifier = "inH2O";
61+
}

0 commit comments

Comments
 (0)