Skip to content

Commit

Permalink
Merge pull request TeamPorcupine#1 from TeamPorcupine/master
Browse files Browse the repository at this point in the history
Merge latest from TeamPorcupine
  • Loading branch information
koosemose authored Apr 11, 2017
2 parents 9af8098 + 99054c6 commit 300ce77
Show file tree
Hide file tree
Showing 53 changed files with 1,806 additions and 1,040 deletions.
217 changes: 217 additions & 0 deletions Assets/Editor/UnitTests/Models/Area/AtmosphereComponentTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
#region License
// ====================================================
// Project Porcupine Copyright(C) 2016 Team Porcupine
// This program comes with ABSOLUTELY NO WARRANTY; This is free software,
// and you are welcome to redistribute it under certain conditions; See
// file LICENSE, which is part of this source code package, for details.
// ====================================================
#endregion

using System;
using NUnit.Framework;

public class AtmosphereComponentTest
{
private AtmosphereComponent empty1, empty2, notEmpty1, notEmpty2;

[SetUp]
public void Setup()
{
empty1 = new AtmosphereComponent();
empty2 = new AtmosphereComponent();

notEmpty1 = new AtmosphereComponent();
notEmpty2 = new AtmosphereComponent();
notEmpty1.CreateGas("gas", 1.0f, 1.0f);
notEmpty2.CreateGas("gas", 2.0f, 2.0f);
}

#region CreateGas
[Test]
public void CreateGas_PositiveAmountAndTemperature_TotalGasIncreasesByValue()
{
empty1.CreateGas("gas", 1.0f, 1.0f);
notEmpty1.CreateGas("gas", 1.0f, 1.0f);

Assert.AreEqual(1.0f, empty1.GetGasAmount());
Assert.AreEqual(2.0f, notEmpty2.GetGasAmount());
}

[Test]
public void CreateGas_PositiveAmountAndTemperature_GasOfTypeIncreasesByValue()
{
empty1.CreateGas("gas", 1.0f, 1.0f);
notEmpty1.CreateGas("gas", 1.0f, 1.0f);

Assert.AreEqual(1.0f, empty1.GetGasAmount("gas"));
Assert.AreEqual(2.0f, notEmpty2.GetGasAmount("gas"));
}

[Test]
public void CreateGas_PositiveAmountAndTemperature_TemperatureIncreasesCorrectly()
{
empty1.CreateGas("gas", 1.0f, 1.0f);
notEmpty1.CreateGas("gas", 1.0f, 1.0f);
notEmpty2.CreateGas("gas", 1.0f, 1.0f);

Assert.AreEqual(1.0f, empty1.GetTemperature());
Assert.AreEqual(1.0f, notEmpty1.GetTemperature());
Assert.AreEqual(5.0f / 3.0f, notEmpty2.GetTemperature());
}

[Test]
public void CreateGas_AmountIsNegative_NoChange()
{
empty1.CreateGas("gas", -1.0f, 1.0f);

Assert.AreEqual(0.0f, empty1.GetGasAmount());
}

[Test]
public void CreateGas_TemperatureIsNegative_NoChange()
{
empty1.CreateGas("gas", 1.0f, -1.0f);

Assert.AreEqual(0.0f, empty1.GetGasAmount());
}
#endregion

#region DestroyGas
[Test]
public void DestroyGas_PositiveAmountBelowTotal_TotalGasDecreasesByValue()
{
notEmpty1.DestroyGas("gas", 0.5f);

Assert.AreEqual(0.5f, notEmpty1.GetGasAmount());
}

[Test]
public void DestroyGas_PositiveAmountBelowTotal_GasOfTypeDecreasesByValue()
{
notEmpty1.DestroyGas("gas", 0.5f);

Assert.AreEqual(0.5f, notEmpty1.GetGasAmount("gas"));
}

[Test]
public void DestroyGas_PositiveAmountBelowTotal_TemperatureStaysTheSame()
{
notEmpty1.DestroyGas("gas", 0.5f);
notEmpty2.DestroyGas("gas", 0.5f);

Assert.AreEqual(1.0f, notEmpty1.GetTemperature());
Assert.AreEqual(2.0f, notEmpty2.GetTemperature());
}

[Test]
public void DestroyGas_AmountIsNegative_NoChange()
{
notEmpty1.DestroyGas("gas", -0.5f);

Assert.AreEqual(1.0f, notEmpty1.GetGasAmount());
}

[Test]
public void DestroyGas_AmountIsAboveTotal_TotalGasDecreasesByAmountOfType()
{
notEmpty1.DestroyGas("gas", 1.5f);
notEmpty2.CreateGas("otherGas", 1.0f, 1.0f);
notEmpty2.DestroyGas("otherGas", 1.5f);

Assert.AreEqual(0.0f, notEmpty1.GetGasAmount());
Assert.AreEqual(2.0f, notEmpty2.GetGasAmount());
}

[Test]
public void DestroyGas_AmountIsAboveTotal_GasOfTypeIsZero()
{
notEmpty1.DestroyGas("gas", 1.5f);

Assert.AreEqual(0.0f, notEmpty1.GetGasAmount("gas"));
}
#endregion

#region MoveGasTo
[Test]
public void MoveGasTo_DestinationIsNull_NoChange()
{
notEmpty1.MoveGasTo(null, 1.0f);

Assert.AreEqual(1.0f, notEmpty1.GetGasAmount());
}

[Test]
public void MoveGasTo_PositiveAmountBelowTotal_SourceTotalDecreasesByValue()
{
notEmpty1.MoveGasTo(empty1, 0.5f);

Assert.AreEqual(0.5f, notEmpty1.GetGasAmount());
}

[Test]
public void MoveGasTo_PositiveAmountBelowTotal_DestinationTotalIncreasesByValue()
{
notEmpty1.MoveGasTo(empty1, 0.5f);

Assert.AreEqual(0.5f, empty1.GetGasAmount());
}

[Test]
public void MoveGasTo_PositiveAmountBelowTotal_SourceGasOfTypeDecreasesByValue()
{
notEmpty1.MoveGasTo(empty1, 0.5f);

Assert.AreEqual(0.5f, notEmpty1.GetGasAmount("gas"));
}

[Test]
public void MoveGasTo_PositiveAmountBelowTotal_DestinationGasOfTypeIncreasesByValue()
{
notEmpty1.MoveGasTo(empty1, 0.5f);

Assert.AreEqual(0.5f, empty1.GetGasAmount("gas"));
}

[Test]
public void MoveGasTo_PositiveAmountBelowTotal_SourceTemperatureStaysTheSame()
{
notEmpty1.MoveGasTo(empty1, 0.5f);

Assert.AreEqual(1.0f, notEmpty1.GetTemperature());
}

[Test]
public void MoveGasTo_PositiveAmountBelowTotal_DestinationTemperatureChangesCorrectly()
{
notEmpty2.MoveGasTo(empty1, 0.5f);
notEmpty2.MoveGasTo(notEmpty1, 0.5f);

Assert.AreEqual(2.0f, empty1.GetTemperature());
Assert.AreEqual(4.0f / 3.0f, notEmpty1.GetTemperature());
}

[Test]
public void MoveGasTo_NegativeAmount_NoChange()
{
notEmpty1.MoveGasTo(empty1, -0.5f);

Assert.AreEqual(1.0f, notEmpty1.GetGasAmount());
}

[Test]
public void MoveGasTo_AmountIsAboveTotal_SourceAmountIsZero()
{
notEmpty1.MoveGasTo(empty1, 1.5f);

Assert.AreEqual(0.0f, notEmpty1.GetGasAmount());
}

[Test]
public void MoveGasTo_AmountIsAboveTotal_DestinationAmountIncreasesBySourceTotal()
{
notEmpty1.MoveGasTo(empty1, 1.5f);

Assert.AreEqual(1.0f, empty1.GetGasAmount());
}
#endregion
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 20 additions & 8 deletions Assets/Editor/UnitTests/Models/BuildableComponentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void TestWorkshopXmlSerialization()

Assert.NotNull(deserializedWorkshop);
Assert.AreEqual("Raw Iron", deserializedWorkshop.PossibleProductions[0].Input[0].ObjectType);
Assert.IsNotNull(deserializedWorkshop.RunConditions);
}

[Test]
Expand Down Expand Up @@ -197,8 +198,8 @@ public void TestPowerConnectionXmlSerialization()
Assert.NotNull(deserializedPowerConnection);

Assert.AreEqual(10f, deserializedPowerConnection.Provides.Rate);
Assert.AreEqual(0f, deserializedPowerConnection.Requires.Rate);
Assert.AreEqual(1, deserializedPowerConnection.Requires.ParamConditions.Count);
Assert.AreEqual("cur_processed_inv", deserializedPowerConnection.RunConditions.ParamConditions[0].ParameterName);
Assert.AreEqual(1, deserializedPowerConnection.RunConditions.ParamConditions.Count);
}

[Test]
Expand All @@ -218,8 +219,8 @@ public void TestPowerConnectionJsonSerialization()
Assert.NotNull(deserializedPowerConnection);

Assert.AreEqual(10f, deserializedPowerConnection.Provides.Rate);
Assert.AreEqual(0f, deserializedPowerConnection.Requires.Rate);
Assert.AreEqual(1, deserializedPowerConnection.Requires.ParamConditions.Count);
Assert.AreEqual("cur_processed_inv", deserializedPowerConnection.RunConditions.ParamConditions[0].ParameterName);
Assert.AreEqual(1, deserializedPowerConnection.RunConditions.ParamConditions.Count);
}

[Test]
Expand Down Expand Up @@ -281,7 +282,7 @@ private static Visuals CreateVisuals()
new BuildableComponent.UseAnimation()
{
Name = "idle",
Requires = new BuildableComponent.ParameterConditions()
RunConditions = new BuildableComponent.Conditions()
{
ParamConditions = new System.Collections.Generic.List<BuildableComponent.ParameterCondition>()
{
Expand All @@ -296,7 +297,7 @@ private static Visuals CreateVisuals()
new BuildableComponent.UseAnimation()
{
Name = "running",
Requires = new BuildableComponent.ParameterConditions()
RunConditions = new BuildableComponent.Conditions()
{
ParamConditions = new System.Collections.Generic.List<BuildableComponent.ParameterCondition>()
{
Expand Down Expand Up @@ -364,6 +365,17 @@ private static Workshop CreateWorkshop()

workshop.PossibleProductions.Add(chain2);

workshop.RunConditions = new BuildableComponent.Conditions()
{
ParamConditions = new System.Collections.Generic.List<BuildableComponent.ParameterCondition>()
{
new BuildableComponent.ParameterCondition()
{
ParameterName = "test", Condition = BuildableComponent.ConditionType.IsTrue
}
}
};

workshop.ParamsDefinitions = new Workshop.WorkShopParameterDefinitions();
return workshop;
}
Expand Down Expand Up @@ -394,8 +406,8 @@ private static PowerConnection CreatePowerConnection()
{
return new PowerConnection
{
Provides = new PowerConnection.Info() { Rate = 10.0f, Capacity = 100.0f },
Requires = new PowerConnection.Info()
Provides = new PowerConnection.Info() { Rate = 10.0f, Capacity = 100.0f },
RunConditions = new BuildableComponent.Conditions()
{
ParamConditions = new System.Collections.Generic.List<BuildableComponent.ParameterCondition>()
{
Expand Down
11 changes: 11 additions & 0 deletions Assets/Editor/UnitTests/Models/Power/PowerGridTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,17 @@ public bool IsProducer

public float OutputRate { get; set; }

public bool InputCanVary { get; set; }

public bool OutputCanVary { get; set; }

public bool OutputIsNeeded { get; set; }

public bool AllRequirementsFulfilled
{
get { return true; }
}

public void Reconnect()
{
throw new NotImplementedException();
Expand Down
11 changes: 11 additions & 0 deletions Assets/Editor/UnitTests/Models/Power/PowerNetworkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ public bool IsProducer

public float OutputRate { get; set; }

public bool InputCanVary { get; set; }

public bool OutputCanVary { get; set; }

public bool OutputIsNeeded { get; set; }

public bool AllRequirementsFulfilled
{
get { return true; }
}

public void Reconnect()
{
throw new NotImplementedException();
Expand Down
2 changes: 1 addition & 1 deletion Assets/Plugins.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Plugins/FMod.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Plugins/Mono Compiler.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 300ce77

Please sign in to comment.