mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-24 17:29:23 +01:00
added some tests
This commit is contained in:
parent
e24c871ecd
commit
702bf94f49
13 changed files with 210 additions and 6 deletions
|
@ -3,7 +3,7 @@
|
|||
"isRoot": true,
|
||||
"tools": {
|
||||
"cake.tool": {
|
||||
"version": "0.38.5",
|
||||
"version": "1.1.0",
|
||||
"commands": [
|
||||
"dotnet-cake"
|
||||
]
|
||||
|
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -3,4 +3,5 @@ bin
|
|||
obj
|
||||
packages
|
||||
*.user
|
||||
tools
|
||||
tools
|
||||
TestResults
|
10
Jenkinsfile
vendored
10
Jenkinsfile
vendored
|
@ -4,7 +4,13 @@ pipeline {
|
|||
stage('Cake Build') {
|
||||
steps {
|
||||
sh 'dotnet tool restore'
|
||||
sh 'dotnet dotnet-cake -Target=Publish -Branch=' + env.BRANCH_NAME
|
||||
sh 'dotnet dotnet-cake --Target=Publish -Branch=' + env.BRANCH_NAME
|
||||
}
|
||||
}
|
||||
stage('Publish Test Results') {
|
||||
steps {
|
||||
nunit testResultsPattern: '**/TestResults.xml'
|
||||
cobertura coberturaReportFile: '**/coverage.cobertura.xml'
|
||||
}
|
||||
}
|
||||
stage('Document') {
|
||||
|
@ -12,7 +18,7 @@ pipeline {
|
|||
branch 'release'
|
||||
}
|
||||
steps {
|
||||
sh 'dotnet dotnet-cake -Target=Document'
|
||||
sh 'dotnet dotnet-cake --Target=Document'
|
||||
sh 'cp Docs/_site/** /var/www/MLEM/ -r'
|
||||
}
|
||||
}
|
||||
|
|
6
MLEM.sln
6
MLEM.sln
|
@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLEM.Templates", "MLEM.Temp
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demos.Android", "Demos.Android\Demos.Android.csproj", "{410C0262-131C-4D0E-910D-D01B4F7143E0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{53D52C3F-67FB-4F32-A794-EAB140BBFC11}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -66,5 +68,9 @@ Global
|
|||
{410C0262-131C-4D0E-910D-D01B4F7143E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{410C0262-131C-4D0E-910D-D01B4F7143E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{410C0262-131C-4D0E-910D-D01B4F7143E0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{53D52C3F-67FB-4F32-A794-EAB140BBFC11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{53D52C3F-67FB-4F32-A794-EAB140BBFC11}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{53D52C3F-67FB-4F32-A794-EAB140BBFC11}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{53D52C3F-67FB-4F32-A794-EAB140BBFC11}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -126,7 +126,7 @@ namespace MLEM.Textures {
|
|||
/// <param name="uv">The top left corner of this area</param>
|
||||
/// <param name="size">The size of this area</param>
|
||||
public TextureRegion(TextureRegion region, Point uv, Point size) :
|
||||
this(region.Texture, region.Position + uv, size) {
|
||||
this(region?.Texture, (region?.Position ?? Point.Zero) + uv, size) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
14
Tests/Content/Texture.atlas
Normal file
14
Tests/Content/Texture.atlas
Normal file
|
@ -0,0 +1,14 @@
|
|||
SimpleDeskUp
|
||||
loc 0 0 48 32
|
||||
piv 16 16
|
||||
SimpleDeskRight
|
||||
loc 48 0 48 32
|
||||
piv 80 16
|
||||
Plant
|
||||
loc 96 0 16 32
|
||||
LongTableUp
|
||||
loc 0 32 64 48
|
||||
piv 16 48
|
||||
LongTableRight
|
||||
loc 64 32 64 48
|
||||
piv 112 48
|
25
Tests/DataTextureAtlasTests.cs
Normal file
25
Tests/DataTextureAtlasTests.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MLEM.Data;
|
||||
using MLEM.Data.Content;
|
||||
using NUnit.Framework;
|
||||
using Tests.Stub;
|
||||
|
||||
namespace Tests {
|
||||
public class TestDataTextureAtlas {
|
||||
|
||||
[Test]
|
||||
public void Test() {
|
||||
var atlas = DataTextureAtlas.LoadAtlasData(null, new RawContentManager(new StubServices()), "Texture.atlas");
|
||||
Assert.AreEqual(atlas.Regions.Count(), 5);
|
||||
|
||||
var table = atlas["LongTableUp"];
|
||||
Assert.AreEqual(table.Area, new Rectangle(0, 32, 64, 48));
|
||||
Assert.AreEqual(table.PivotPixels, new Vector2(16, 48 - 32));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
35
Tests/FormattingTests.cs
Normal file
35
Tests/FormattingTests.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MLEM.Formatting;
|
||||
using MLEM.Formatting.Codes;
|
||||
using MLEM.Textures;
|
||||
using NUnit.Framework;
|
||||
using Tests.Stub;
|
||||
|
||||
namespace Tests {
|
||||
public class FormattingTests {
|
||||
|
||||
[Test]
|
||||
public void TestMacros() {
|
||||
var formatter = new TextFormatter();
|
||||
formatter.Macros.Add(new Regex("<testmacro>"), (f, m, r) => "<test1>");
|
||||
formatter.Macros.Add(new Regex("<test1>"), (f, m, r) => "<test2>blue");
|
||||
formatter.Macros.Add(new Regex("<test2>"), (f, m, r) => "<c Blue>");
|
||||
const string strg = "This text uses a bunch of non-breaking~spaces to see if macros work. Additionally, it uses a macro that resolves into a bunch of other macros and then, at the end, into <testmacro> text</c>.";
|
||||
const string goal = "This text uses a bunch of non-breaking\u00A0spaces to see if macros work. Additionally, it uses a macro that resolves into a bunch of other macros and then, at the end, into <c Blue>blue text</c>.";
|
||||
Assert.AreEqual(formatter.ResolveMacros(strg), goal);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFormatting() {
|
||||
var formatter = new TextFormatter();
|
||||
formatter.AddImage("Test", new TextureRegion((Texture2D) null, 0, 8, 24, 24));
|
||||
const string strg = "Lorem Ipsum <i Test> is simply dummy text of the <i Test> printing and typesetting <i Test> industry. Lorem Ipsum has been the industry's standard dummy text <i Test> ever since the <i Test> 1500s, when <i Test><i Test><i Test><i Test><i Test><i Test><i Test> an unknown printer took a galley of type and scrambled it to make a type specimen book.";
|
||||
var ret = formatter.Tokenize(new StubFont(), strg);
|
||||
Assert.AreEqual(ret.Tokens.Length, 13);
|
||||
Assert.AreEqual(ret.DisplayString, "Lorem Ipsum \u2003 is simply dummy text of the \u2003 printing and typesetting \u2003 industry. Lorem Ipsum has been the industry's standard dummy text \u2003 ever since the \u2003 1500s, when \u2003\u2003\u2003\u2003\u2003\u2003\u2003 an unknown printer took a galley of type and scrambled it to make a type specimen book.");
|
||||
Assert.AreEqual(ret.AllCodes.Length, 12);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
36
Tests/NumberTests.cs
Normal file
36
Tests/NumberTests.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using MLEM.Extensions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Tests {
|
||||
public class NumberTests {
|
||||
|
||||
[Test]
|
||||
public void TestRounding() {
|
||||
Assert.AreEqual(1.25F.Floor(), 1);
|
||||
Assert.AreEqual(-1.25F.Floor(), -1);
|
||||
|
||||
Assert.AreEqual(1.25F.Ceil(), 2);
|
||||
Assert.AreEqual(-1.25F.Ceil(), -2);
|
||||
|
||||
Assert.AreEqual(new Vector2(5, 2.5F).FloorCopy(), new Vector2(5, 2));
|
||||
Assert.AreEqual(new Vector2(5, 2.5F).CeilCopy(), new Vector2(5, 3));
|
||||
Assert.AreEqual(new Vector2(5.25F, 2).FloorCopy(), new Vector2(5, 2));
|
||||
Assert.AreEqual(new Vector2(5.25F, 2).CeilCopy(), new Vector2(6, 2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEquals() {
|
||||
Assert.IsTrue(0.25F.Equals(0.26F, 0.01F));
|
||||
Assert.IsFalse(0.25F.Equals(0.26F, 0.009F));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMatrixOps() {
|
||||
var matrix = Matrix.CreateRotationX(2) * Matrix.CreateScale(2.5F);
|
||||
Assert.AreEqual(matrix.Scale(), new Vector3(2.5F));
|
||||
Assert.AreEqual(matrix.Rotation(), Quaternion.CreateFromAxisAngle(Vector3.UnitX, 2));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
36
Tests/Stub/StubFont.cs
Normal file
36
Tests/Stub/StubFont.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MLEM.Font;
|
||||
|
||||
namespace Tests.Stub {
|
||||
public class StubFont : GenericFont {
|
||||
|
||||
public override GenericFont Bold => this;
|
||||
public override GenericFont Italic => this;
|
||||
public override float LineHeight => 1;
|
||||
|
||||
protected override Vector2 MeasureChar(char c) {
|
||||
return Vector2.Zero;
|
||||
}
|
||||
|
||||
public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color) {
|
||||
}
|
||||
|
||||
public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) {
|
||||
}
|
||||
|
||||
public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) {
|
||||
}
|
||||
|
||||
public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color) {
|
||||
}
|
||||
|
||||
public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) {
|
||||
}
|
||||
|
||||
public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Tests/Stub/StubServices.cs
Normal file
11
Tests/Stub/StubServices.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
|
||||
namespace Tests.Stub {
|
||||
public class StubServices : IServiceProvider {
|
||||
|
||||
public object GetService(Type serviceType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
27
Tests/Tests.csproj
Normal file
27
Tests/Tests.csproj
Normal file
|
@ -0,0 +1,27 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<VSTestLogger>nunit</VSTestLogger>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MLEM.Ui\MLEM.Ui.csproj" />
|
||||
<ProjectReference Include="..\MLEM.Data\MLEM.Data.csproj" />
|
||||
<ProjectReference Include="..\MLEM\MLEM.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.3" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
|
||||
<PackageReference Include="NUnit" Version="3.13.1" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
||||
<PackageReference Include="NunitXml.TestLogger" Version="3.0.97" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Content/**">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -29,7 +29,14 @@ Task("Build").IsDependentOn("Prepare").Does(() =>{
|
|||
DotNetCoreBuild("Demos/Demos.csproj", settings);
|
||||
});
|
||||
|
||||
Task("Pack").IsDependentOn("Build").Does(() => {
|
||||
Task("Test").IsDependentOn("Build").Does(() => {
|
||||
DotNetCoreTest("Tests/Tests.csproj", new DotNetCoreTestSettings {
|
||||
Configuration = config,
|
||||
Collectors = {"XPlat Code Coverage"}
|
||||
});
|
||||
});
|
||||
|
||||
Task("Pack").IsDependentOn("Test").Does(() => {
|
||||
var settings = new DotNetCorePackSettings {
|
||||
Configuration = config,
|
||||
ArgumentCustomization = args => args.Append($"/p:Version={version}")
|
||||
|
|
Loading…
Reference in a new issue