Skip to content

Commit

Permalink
Add TerraForM test project. Add CI action to build and test sln
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbaxon committed Nov 14, 2021
1 parent 30f81c7 commit fe3a67f
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 39 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build and test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
11 changes: 11 additions & 0 deletions ConsoleEngine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Engine", "Engine", "{12D2B4
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerraForM", "Examples\TerraForM\TerraForM.csproj", "{0CDE38D4-12F4-426B-9252-E57820FF8D9B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D4D32729-A0A7-4446-966C-9CD59236634B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerraForM.Tests", "Examples\TerraForM.Tests\TerraForM.Tests.csproj", "{58BE9E1E-1B58-423F-B2BF-9DB66E0CFACA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples.Tests", "Examples.Tests", "{106CCD57-88BD-4B0A-A67F-A5DA7D8FCA3C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Release|Any CPU = Release|Any CPU
Expand Down Expand Up @@ -72,6 +78,10 @@ Global
{276379A8-897A-4703-A18D-9DB3A08A09AA}.Release|Any CPU.Build.0 = Release|Any CPU
{276379A8-897A-4703-A18D-9DB3A08A09AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{276379A8-897A-4703-A18D-9DB3A08A09AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58BE9E1E-1B58-423F-B2BF-9DB66E0CFACA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58BE9E1E-1B58-423F-B2BF-9DB66E0CFACA}.Release|Any CPU.Build.0 = Release|Any CPU
{58BE9E1E-1B58-423F-B2BF-9DB66E0CFACA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58BE9E1E-1B58-423F-B2BF-9DB66E0CFACA}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{99309207-1847-4EB9-A009-C7B92BC2CE64} = {CA22425D-FB6C-45C6-A14C-561DF6D969B6}
Expand All @@ -85,5 +95,6 @@ Global
{CC763EA2-7C5E-45C2-948C-BA0279D3C04F} = {12D2B48F-E7F6-4BEC-8315-9EC8F41A059A}
{A4209E56-1ECD-4616-BB13-DF77864F462C} = {12D2B48F-E7F6-4BEC-8315-9EC8F41A059A}
{0CDE38D4-12F4-426B-9252-E57820FF8D9B} = {028D7499-6A31-4A9F-868A-908AD53A8BD0}
{58BE9E1E-1B58-423F-B2BF-9DB66E0CFACA} = {106CCD57-88BD-4B0A-A67F-A5DA7D8FCA3C}
EndGlobalSection
EndGlobal
33 changes: 33 additions & 0 deletions Examples/TerraForM.Tests/RoverTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Linq;
using NSubstitute;
using NUnit.Framework;
using TerraForM;
using TerraForM.Commands;
using TerraForM.GameObjects;
using TerraForM.GameObjects.Tiles;

namespace TerraForM.Tests
{
public class Tests
{
[SetUp]
public void Setup()
{
}

[Test]
public void Rover_PowerIsDepletedWhenRemainingPowerIsZeroOrLess()
{
var game = Substitute.For<TerraformGame>();
var world = Substitute.For<World>();
world.MaxPower = 10000;
world.Sequences = 30;
game.World = world;

var sut = new Rover(game);
sut.RemainingPower -= world.MaxPower;
Assert.That(sut.PowerDepleted(), Is.True);
}
}
}

22 changes: 22 additions & 0 deletions Examples/TerraForM.Tests/TerraForM.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TerraForM\TerraForM.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Examples/TerraForM/GameObjects/PlantEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void Draw()
{
var screenPos = Game.Camera.WorldToScreenPos(pos).ToPoint();

if (Game.Console.GetCharAt(screenPos.X, screenPos.Y) == ' ');
if (Game.Console.GetCharAt(screenPos.X, screenPos.Y) == ' ')
Game.Console.Draw(screenPos.X, screenPos.Y, Grass);
}
}
Expand Down
27 changes: 0 additions & 27 deletions Examples/TerraForM/Music.cs

This file was deleted.

9 changes: 0 additions & 9 deletions Examples/TerraForM/TerraformGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ protected override void OnInitialize()

Hud = new Hud(this);
Camera.Follow(Rover);

new Task(async () =>
{
await Music.PlayIntroMusic();
}).Start();
}

private void StartNewGame()
Expand Down Expand Up @@ -100,10 +95,6 @@ protected override void OnUpdate()
if (Rover.PowerDepleted() || Rover.RemainingSequences < 0)
{
GameOver = true;
new Task(async () =>
{
await Music.PlayGameOverMusic();
}).Start();
}

Hud.OnUpdate();
Expand Down
5 changes: 3 additions & 2 deletions Examples/TerraForM/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public class World
private readonly int _mapWidth;
private readonly int _mapHeight;
public const int TileSize = 5;




public World(){}
public World(TerraformGame game, string name, MapTile[,] map) {
_game = game;
_tiles = map;
Expand Down

0 comments on commit fe3a67f

Please sign in to comment.