Skip to content

Commit

Permalink
Removed namespaces that were not used
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLarsson committed Oct 22, 2014
1 parent c238ca7 commit 2e19352
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 197 deletions.
27 changes: 13 additions & 14 deletions Gu.Units.Generator.Tests/MockSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
public class MockSettings : Settings
{
public readonly string Namespace = "Gu.Units";
public readonly SiUnit Metres;
public readonly Quantity Length;

Expand Down Expand Up @@ -32,7 +31,7 @@ public class MockSettings : Settings

public readonly DerivedUnit Watts;
public readonly Quantity Power;

public readonly DerivedUnit Volts;
public readonly Quantity Voltage;

Expand All @@ -41,31 +40,31 @@ public class MockSettings : Settings

public MockSettings()
{
Metres = new SiUnit(Namespace, "Metres", "m") { QuantityName = "Length" };
Metres = new SiUnit("Metres", "m") { QuantityName = "Length" };
SiUnits.Add(Metres);
Length = Metres.Quantity;

Seconds = new SiUnit(Namespace, "Seconds", "s") { QuantityName = "Time" };
Seconds = new SiUnit("Seconds", "s") { QuantityName = "Time" };
SiUnits.Add(Seconds);
Time = Seconds.Quantity;

Kilograms = new SiUnit("", "Kilograms", "kg") { QuantityName = "Mass" };
Kilograms = new SiUnit("Kilograms", "kg") { QuantityName = "Mass" };
SiUnits.Add(Kilograms);
Mass = Kilograms.Quantity;

Amperes = new SiUnit("", "Amperes", "A") { QuantityName = "ElectricalCurrent" };
Amperes = new SiUnit("Amperes", "A") { QuantityName = "ElectricalCurrent" };
SiUnits.Add(Amperes);
Current = Amperes.Quantity;

MetresPerSecond = new DerivedUnit(Namespace,
MetresPerSecond = new DerivedUnit(
"MetresPerSecond",
"m/s",
new UnitAndPower(Metres, 1),
new UnitAndPower(Seconds, -1)) { QuantityName = "Speed" };
DerivedUnits.Add(MetresPerSecond);
Speed = MetresPerSecond.Quantity;

Newtons = new DerivedUnit(Namespace,
Newtons = new DerivedUnit(
"Newtons",
"N",
new UnitAndPower(Kilograms, 1),
Expand All @@ -74,46 +73,46 @@ public MockSettings()
DerivedUnits.Add(Newtons);
Force = Newtons.Quantity;

Joules = new DerivedUnit(Namespace,
Joules = new DerivedUnit(
"Joules",
"J",
new UnitAndPower(Newtons, 1),
new UnitAndPower(Metres, 1)) { QuantityName = "Energy" };
DerivedUnits.Add(Joules);
Energy = Joules.Quantity;

Watts = new DerivedUnit(Namespace,
Watts = new DerivedUnit(
"Watts",
"W",
new UnitAndPower(Joules, 1),
new UnitAndPower(Seconds, -1)) { QuantityName = "Power" };
DerivedUnits.Add(Watts);
Power = Watts.Quantity;

Volts = new DerivedUnit(Namespace,
Volts = new DerivedUnit(
"Volts",
"V",
new UnitAndPower(Watts, 1),
new UnitAndPower(Amperes, -1)) { QuantityName = "Voltage" };
DerivedUnits.Add(Volts);
Voltage = Volts.Quantity;

Coloumbs = new DerivedUnit(Namespace,
Coloumbs = new DerivedUnit(
"Coloumbs",
"C",
new UnitAndPower(Seconds, 1),
new UnitAndPower(Amperes, 1)) { QuantityName = "ElectricCharge" };
DerivedUnits.Add(Coloumbs);
ElectricCharge = Coloumbs.Quantity;

SquareMetres = new DerivedUnit(Namespace, "SquareMetres", "m^2", new UnitAndPower(Metres, 2))
SquareMetres = new DerivedUnit("SquareMetres", "m^2", new UnitAndPower(Metres, 2))
{
QuantityName = "Area"
};
DerivedUnits.Add(SquareMetres);
Area = SquareMetres.Quantity;

CubicMetres = new DerivedUnit(Namespace, "CubicMetres", "m^3", new UnitAndPower(Metres, 3))
CubicMetres = new DerivedUnit("CubicMetres", "m^3", new UnitAndPower(Metres, 3))
{
QuantityName = "Volume"
};
Expand Down
8 changes: 3 additions & 5 deletions Gu.Units.Generator.Tests/QuantityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
public class QuantityTests
{
private IUnit _metres;
private string Namespace;
private IUnit _seconds;
private MockSettings _settings;
[SetUp]
Expand All @@ -16,7 +15,6 @@ public void SetUp()
_settings = new MockSettings();
_metres = _settings.Metres;
_seconds = _settings.Seconds;
Namespace = _settings.Namespace;
}

[TestCase("Length", "IQuantity<LengthUnit, I1>")]
Expand All @@ -33,7 +31,7 @@ public void BaseQuantityInterface(string quantityName, string expected)
public void PowerQuantityInterface(int power, string expected)
{
var unitAndPower = new UnitAndPower(_metres, power);
var derivedUnit = new DerivedUnit(Namespace, "sdf", "ssf", unitAndPower) { QuantityName = "Qty" };
var derivedUnit = new DerivedUnit("sdf", "ssf", unitAndPower) { QuantityName = "Qty" };
var quantity = new Quantity(derivedUnit);
var @interface = quantity.Interface;
Assert.AreEqual(expected, @interface);
Expand All @@ -46,8 +44,8 @@ public void ComposedQuantityInterface(int p1, int p2, string expected)
var unitAndPower2 = new UnitAndPower(_seconds, p2);
var quantities = new[]
{
new Quantity(new DerivedUnit("", "", "", unitAndPower1, unitAndPower2)),
new Quantity(new DerivedUnit("", "", "", unitAndPower2, unitAndPower1))
new Quantity(new DerivedUnit("", "", unitAndPower1, unitAndPower2)),
new Quantity(new DerivedUnit("", "", unitAndPower2, unitAndPower1))
};
foreach (var quantity in quantities)
{
Expand Down
28 changes: 6 additions & 22 deletions Gu.Units.Generator/Descriptors/Conversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public Conversion()
_formula = new ConversionFormula(this);
}

public Conversion(string @namespace, string className, string symbol)
: base(@namespace, className)
public Conversion(string className, string symbol)
: base(className)
{
_symbol = symbol;
_formula = new ConversionFormula(this);
Expand All @@ -46,23 +46,6 @@ public string Symbol
}
}

public double ConversionFactor
{
get
{
return _formula.ConversionFactor;
}
set
{
if (value == _formula.ConversionFactor)
{
return;
}
_formula.ConversionFactor = value;
this.OnPropertyChanged();
}
}

public ConversionFormula Formula
{
get { return _formula; }
Expand Down Expand Up @@ -150,6 +133,7 @@ public ObservableCollection<Conversion> Conversions
{
get { return _conversions; }
}

public bool AnyOffsetConversion
{
get { return Conversions.Any(x => x.Formula.Offset != 0); }
Expand All @@ -172,7 +156,7 @@ private void SyncWithPrefix()
{
return;
}
ConversionFactor = Math.Pow(10, _prefix.Power);
Formula.ConversionFactor = Math.Pow(10, _prefix.Power);
if (string.IsNullOrEmpty(Symbol))
{
Symbol = Prefix.Symbol + BaseUnit.Symbol;
Expand All @@ -195,10 +179,10 @@ public void SetParts(IEnumerable<Conversion> subunits)
foreach (var part in subunits)
{
var up = unitParts.Single(x => x.UnitName == part.BaseUnit.ClassName);
cf = cf * Math.Pow(part.ConversionFactor, up.Power);
cf = cf * Math.Pow(part.Formula.ConversionFactor, up.Power);
unitParts.Replace(up, new UnitAndPower(part, up.Power));
}
ConversionFactor = cf;
Formula.ConversionFactor = cf;
ClassName = unitParts.UnitName;
Symbol = unitParts.Expression;
}
Expand Down
6 changes: 3 additions & 3 deletions Gu.Units.Generator/Descriptors/DerivedUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class DerivedUnit : UnitBase
private readonly UnitParts _parts;

public DerivedUnit()
: base(null, null, null)
: base(null, null)
{
_parts = new UnitParts(this);
}

public DerivedUnit(string @namespace, string name, string symbol, params UnitAndPower[] parts)
: base(@namespace, name, symbol)
public DerivedUnit(string name, string symbol, params UnitAndPower[] parts)
: base(name, symbol)
{
_parts = new UnitParts(this);
if (parts.Length == 0)
Expand Down
1 change: 0 additions & 1 deletion Gu.Units.Generator/Descriptors/IUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public interface IUnit : INotifyPropertyChanged
{
string Symbol { get; set; }
string ClassName { get; set; }
string Namespace { get; set; }
string ParameterName { get; }
string QuantityName { get; set; }
Quantity Quantity { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Gu.Units.Generator/Descriptors/Quantity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Quantity : TypeMetaData
private string _unitName;

public Quantity(IUnit unit)
: base(unit.Namespace, null)
: base(null)
{
_unit = unit;
_unit.Quantity = this;
Expand Down
6 changes: 3 additions & 3 deletions Gu.Units.Generator/Descriptors/SiUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
public class SiUnit : UnitBase
{
public SiUnit()
: base(null, null, null)
: base(null, null)
{
}

public SiUnit(string @namespace, string name, string symbol)
: base(@namespace, name, symbol)
public SiUnit(string name, string symbol)
: base(name, symbol)
{
}

Expand Down
20 changes: 1 addition & 19 deletions Gu.Units.Generator/Descriptors/TypeMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,18 @@
public class TypeMetaData : MarshalByRefObject, INotifyPropertyChanged
{
private string _className;
private string _ns;

protected TypeMetaData()
{
}

public TypeMetaData(string @namespace,string className)
public TypeMetaData(string className)
{
_ns = @namespace;
_className = className;
}

public event PropertyChangedEventHandler PropertyChanged;

public virtual string Namespace
{
get { return _ns; }
set
{
if (value == _ns)
{
return;
}
_ns = value;
OnPropertyChanged();
}
}

public string Ns { get; set; }

public string ClassName
{
get { return _className; }
Expand Down
4 changes: 2 additions & 2 deletions Gu.Units.Generator/Descriptors/UnitBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ protected UnitBase()
Quantity = new Quantity(this);
}

protected UnitBase(string @namespace, string className, string symbol)
: base(@namespace, className)
protected UnitBase(string className, string symbol)
: base(className)
{
_conversions = new ParentCollection<UnitBase, Conversion>(this, (unit, parent) => unit.BaseUnit = parent);
Quantity = new Quantity(this);
Expand Down
Loading

0 comments on commit 2e19352

Please sign in to comment.