Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow, revolution, Pressure, Localization, Unittests #7

Merged
merged 4 commits into from
Nov 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions Src/UnitsNet/Flow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using System;
using System.Globalization;

namespace UnitsNet
{
/// <summary>
/// A class for representing flow.
/// </summary>
public struct Flow : IComparable, IComparable<Flow>
{
private const double SecondToMinuteRatio = 60;
private const double SecondToHourRatio = 3600;

public readonly double CubicMeterPerSecond;

private Flow(double cubicMeterPerSecond)
: this()
{
CubicMeterPerSecond = cubicMeterPerSecond;
}

public double CubicMeterPerHour
{
get { return CubicMeterPerSecond / SecondToHourRatio; }
}

#region Static

public static Flow Zero
{
get { return new Flow(); }
}

public static Flow FromCubicMeterPerHour(double cmh)
{
return new Flow(cmh * SecondToHourRatio);
}

public static Flow FromCubicMeterPerSecond(double cms)
{
return new Flow(cms);
}

#endregion

#region Equality / IComparable

public int CompareTo(object obj)
{
if (obj == null) throw new ArgumentNullException("obj");
if (!(obj is Flow)) throw new ArgumentException("Expected type Flow.", "obj");
return CompareTo((Flow)obj);
}

public int CompareTo(Flow other)
{
return CubicMeterPerSecond.CompareTo(other.CubicMeterPerSecond);
}

public static bool operator <=(Flow left, Flow right)
{
return left.CubicMeterPerSecond <= right.CubicMeterPerSecond;
}

public static bool operator >=(Flow left, Flow right)
{
return left.CubicMeterPerSecond >= right.CubicMeterPerSecond;
}

public static bool operator <(Flow left, Flow right)
{
return left.CubicMeterPerSecond < right.CubicMeterPerSecond;
}

public static bool operator >(Flow left, Flow right)
{
return left.CubicMeterPerSecond > right.CubicMeterPerSecond;
}

public static bool operator ==(Flow left, Flow right)
{
return left.CubicMeterPerSecond == right.CubicMeterPerSecond;
}

public static bool operator !=(Flow left, Flow right)
{
return left.CubicMeterPerSecond != right.CubicMeterPerSecond;
}

public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}

return CubicMeterPerSecond.Equals(((Flow)obj).CubicMeterPerSecond);
}

public override int GetHashCode()
{
return CubicMeterPerSecond.GetHashCode();
}
#endregion

#region Arithmetic operators

public static Flow operator -(Flow right)
{
return new Flow(-right.CubicMeterPerSecond);
}

public static Flow operator +(Flow left, Flow right)
{
return new Flow(left.CubicMeterPerSecond + right.CubicMeterPerSecond);
}

public static Flow operator -(Flow left, Flow right)
{
return new Flow(left.CubicMeterPerSecond - right.CubicMeterPerSecond);
}

public static Flow operator *(double left, Flow right)
{
return new Flow(left * right.CubicMeterPerSecond);
}

public static Flow operator *(Flow left, double right)
{
return new Flow(left.CubicMeterPerSecond * right);
}

public static Flow operator /(Flow left, double right)
{
return new Flow(left.CubicMeterPerSecond / right);
}

public static double operator /(Flow left, Flow right)
{
return left.CubicMeterPerSecond / right.CubicMeterPerSecond;
}

#endregion

public override string ToString()
{
return CubicMeterPerSecond + " " + UnitSystem.Create(CultureInfo.CurrentCulture).GetDefaultAbbreviation(Unit.CubicMeterPerSecond);
}
}
}
22 changes: 22 additions & 0 deletions Src/UnitsNet/Pressure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace UnitsNet
public struct Pressure : IComparable, IComparable<Pressure>
{
private const double KpaToPaRatio = 1000;
private const double MpaToPaRatio = 1000000;
private const double Nm2ToPaRatio = 1;
private const double Ncm2ToPaRatio = 1E+4;
private const double Nmm2ToPaRatio = 1E+6;
Expand All @@ -38,6 +39,7 @@ public struct Pressure : IComparable, IComparable<Pressure>
private const double AtmToPaRatio = 101325;
private const double TorrToPaRatio = 1.3332266752*1E2;
private const double PsiToPaRatio = 6.89464975179*1E3;
private const double KFSCToPaRatio = 98066.5;

/// <summary>
/// Pressure in pascal.
Expand All @@ -56,6 +58,16 @@ public double KiloPascals
get { return Pascals/KpaToPaRatio; }
}

public double MegaPascals
{
get { return Pascals / MpaToPaRatio; }
}

public double KilogramForcePerSquareCentimeter
{
get { return Pascals / KFSCToPaRatio; }
}

public double NewtonsPerSquareMeter
{
get { return Pascals/Nm2ToPaRatio; }
Expand Down Expand Up @@ -131,6 +143,16 @@ public static Pressure FromKiloPascals(double kpa)
return new Pressure(KpaToPaRatio*kpa);
}

public static Pressure FromMegaPascals(double mpa)
{
return new Pressure(MpaToPaRatio * mpa);
}

public static Pressure FromKilogramForcePerSquareCentimeter(double kfsc)
{
return new Pressure(KFSCToPaRatio * kfsc);
}

public static Pressure FromNewtonsPerSquareCentimeter(double nsc)
{
return new Pressure(Ncm2ToPaRatio*nsc);
Expand Down
150 changes: 150 additions & 0 deletions Src/UnitsNet/Revolution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using System;
using System.Globalization;

namespace UnitsNet
{
/// <summary>
/// A class for representing revolution.
/// </summary>
public struct Revolution : IComparable, IComparable<Revolution>
{
private const double MinuteToSecondRatio = 0.0166666666666667;
private const double SecondToMinuteRatio = 60;

public readonly double RevolutionsPerSecond;

private Revolution(double revolutionsPerSecond)
: this()
{
RevolutionsPerSecond = revolutionsPerSecond;
}

public double RevolutionsPerMinute
{
get { return RevolutionsPerSecond * SecondToMinuteRatio; }
}

#region Static

public static Revolution Zero
{
get { return new Revolution(); }
}

public static Revolution FromRevolutionsPerMinute(double revolutionsPerMinute)
{
return new Revolution(revolutionsPerMinute * MinuteToSecondRatio);
}

public static Revolution FromRevolutionsPerSecond(double revolutionsPerSecond)
{
return new Revolution(revolutionsPerSecond);
}

#endregion

#region Equality / IComparable

public int CompareTo(object obj)
{
if (obj == null) throw new ArgumentNullException("obj");
if (!(obj is Revolution)) throw new ArgumentException("Expected type Revolution.", "obj");
return CompareTo((Revolution)obj);
}

public int CompareTo(Revolution other)
{
return RevolutionsPerSecond.CompareTo(other.RevolutionsPerSecond);
}

public static bool operator <=(Revolution left, Revolution right)
{
return left.RevolutionsPerSecond <= right.RevolutionsPerSecond;
}

public static bool operator >=(Revolution left, Revolution right)
{
return left.RevolutionsPerSecond >= right.RevolutionsPerSecond;
}

public static bool operator <(Revolution left, Revolution right)
{
return left.RevolutionsPerSecond < right.RevolutionsPerSecond;
}

public static bool operator >(Revolution left, Revolution right)
{
return left.RevolutionsPerSecond > right.RevolutionsPerSecond;
}

public static bool operator ==(Revolution left, Revolution right)
{
return left.RevolutionsPerSecond == right.RevolutionsPerSecond;
}

public static bool operator !=(Revolution left, Revolution right)
{
return left.RevolutionsPerSecond != right.RevolutionsPerSecond;
}

public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}

return RevolutionsPerSecond.Equals(((Revolution)obj).RevolutionsPerSecond);
}

public override int GetHashCode()
{
return RevolutionsPerSecond.GetHashCode();
}
#endregion

#region Arithmetic operators

public static Revolution operator -(Revolution right)
{
return new Revolution(-right.RevolutionsPerSecond);
}

public static Revolution operator +(Revolution left, Revolution right)
{
return new Revolution(left.RevolutionsPerSecond + right.RevolutionsPerSecond);
}

public static Revolution operator -(Revolution left, Revolution right)
{
return new Revolution(left.RevolutionsPerSecond - right.RevolutionsPerSecond);
}

public static Revolution operator *(double left, Revolution right)
{
return new Revolution(left * right.RevolutionsPerSecond);
}

public static Revolution operator *(Revolution left, double right)
{
return new Revolution(left.RevolutionsPerSecond * right);
}

public static Revolution operator /(Revolution left, double right)
{
return new Revolution(left.RevolutionsPerSecond / right);
}

public static double operator /(Revolution left, Revolution right)
{
return left.RevolutionsPerSecond / right.RevolutionsPerSecond;
}

#endregion

public override string ToString()
{
return RevolutionsPerSecond + " " + UnitSystem.Create(CultureInfo.CurrentCulture).GetDefaultAbbreviation(Unit.RevolutionsPerSecond);
}
}
}
12 changes: 11 additions & 1 deletion Src/UnitsNet/Unit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ public enum Unit
// Pressure
Pascal,
KiloPascal,
MegaPascal,
Psi,
NewtonPerSquareCentimeter,
NewtonPerSquareMillimeter,
NewtonPerSquareMeter,
Bar,
Bar,
TechnicalAtmosphere,
Atmosphere,
Torr,
KilogramForcePerSquareCentimeter,

// Force
Kilonewton,
Expand Down Expand Up @@ -162,6 +164,14 @@ public enum Unit
// Cooking units
Tablespoon,
Teaspoon,

// Flow
CubicMeterPerSecond,
CubicMeterPerHour,

// Revolution
RevolutionsPerSecond,
RevolutionsPerMinute,
}

//public enum LengthUnit
Expand Down
Loading