This repository has been archived by the owner on Jun 25, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from AlanRynne/development
Unit tests with xUnit and Travis-CI
- Loading branch information
Showing
58 changed files
with
2,027 additions
and
708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
// Use IntelliSense to find out which attributes exist for C# debugging | ||
// Use hover for the description of the existing attributes | ||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": ".NET Core Launch (console)", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build", | ||
// If you have changed target frameworks, make sure to update the program path. | ||
"program": "${workspaceFolder}/AR_Lib.Tests/bin/Debug/netcoreapp2.2/AR_Lib.Tests.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/AR_Lib.Tests", | ||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console | ||
"console": "internalConsole", | ||
"stopAtEntry": false | ||
}, | ||
{ | ||
"name": ".NET Core Attach", | ||
"type": "coreclr", | ||
"request": "attach", | ||
"processId": "${command:pickProcess}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/AR_Lib.Tests/AR_Lib.Tests.csproj" | ||
], | ||
"problemMatcher": "$tsc" | ||
}, | ||
{ | ||
"label": "publish", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"publish", | ||
"${workspaceFolder}/AR_Lib.Tests/AR_Lib.Tests.csproj" | ||
], | ||
"problemMatcher": "$tsc" | ||
}, | ||
{ | ||
"label": "watch", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"watch", | ||
"run", | ||
"${workspaceFolder}/AR_Lib.Tests/AR_Lib.Tests.csproj" | ||
], | ||
"problemMatcher": "$tsc" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AR_Lib", "AR_Lib\AR_Lib.csproj", "{FD765C61-21BE-47EF-A9D0-3098534472F2}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AR_Lib.Tests", "AR_Lib.Tests\AR_Lib.Tests.csproj", "{C2382EC6-F096-4E84-8057-A1507E62310F}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FD765C61-21BE-47EF-A9D0-3098534472F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FD765C61-21BE-47EF-A9D0-3098534472F2}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FD765C61-21BE-47EF-A9D0-3098534472F2}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{FD765C61-21BE-47EF-A9D0-3098534472F2}.Debug|x64.Build.0 = Debug|Any CPU | ||
{FD765C61-21BE-47EF-A9D0-3098534472F2}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{FD765C61-21BE-47EF-A9D0-3098534472F2}.Debug|x86.Build.0 = Debug|Any CPU | ||
{FD765C61-21BE-47EF-A9D0-3098534472F2}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FD765C61-21BE-47EF-A9D0-3098534472F2}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{FD765C61-21BE-47EF-A9D0-3098534472F2}.Release|x64.ActiveCfg = Release|Any CPU | ||
{FD765C61-21BE-47EF-A9D0-3098534472F2}.Release|x64.Build.0 = Release|Any CPU | ||
{FD765C61-21BE-47EF-A9D0-3098534472F2}.Release|x86.ActiveCfg = Release|Any CPU | ||
{FD765C61-21BE-47EF-A9D0-3098534472F2}.Release|x86.Build.0 = Release|Any CPU | ||
{C2382EC6-F096-4E84-8057-A1507E62310F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C2382EC6-F096-4E84-8057-A1507E62310F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C2382EC6-F096-4E84-8057-A1507E62310F}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{C2382EC6-F096-4E84-8057-A1507E62310F}.Debug|x64.Build.0 = Debug|Any CPU | ||
{C2382EC6-F096-4E84-8057-A1507E62310F}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{C2382EC6-F096-4E84-8057-A1507E62310F}.Debug|x86.Build.0 = Debug|Any CPU | ||
{C2382EC6-F096-4E84-8057-A1507E62310F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C2382EC6-F096-4E84-8057-A1507E62310F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{C2382EC6-F096-4E84-8057-A1507E62310F}.Release|x64.ActiveCfg = Release|Any CPU | ||
{C2382EC6-F096-4E84-8057-A1507E62310F}.Release|x64.Build.0 = Release|Any CPU | ||
{C2382EC6-F096-4E84-8057-A1507E62310F}.Release|x86.ActiveCfg = Release|Any CPU | ||
{C2382EC6-F096-4E84-8057-A1507E62310F}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" /> | ||
<PackageReference Include="xunit" Version="2.4.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\AR_Lib\AR_Lib.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using AR_Lib.Geometry; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace AR_Lib.Tests.Geometry | ||
{ | ||
public class Point3dEqualDataset : IEnumerable<object[]> | ||
{ | ||
public IEnumerator<object[]> GetEnumerator() | ||
{ | ||
yield return new object[] { new Point3d(1, 1, 1), new Point3d(1, 1, 1) }; | ||
yield return new object[] { new Point3d(2, 2, -1), new Point3d(2, 2, -1) }; | ||
} | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using AR_Lib.Geometry; | ||
using Xunit; | ||
|
||
namespace AR_Lib.Tests.Geometry | ||
{ | ||
public class Point3dTests | ||
{ | ||
[Theory] | ||
[ClassData(typeof(Point3dEqualDataset))] | ||
public void EqualsAndHashCode_HaveConsistentResults(Point3d pt, Point3d pt2) | ||
{ | ||
bool b1 = (pt == pt2); | ||
bool b2 = (pt.GetHashCode() == pt2.GetHashCode()); | ||
|
||
Assert.True(b1 && b1 == b2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace AR_Lib.Tests.Geometry | ||
{ | ||
public class Vector3dTests | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Reflection; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using Xunit.Sdk; | ||
|
||
namespace AR_Lib.Tests | ||
{ | ||
/// <summary> | ||
/// Data Attribute to extract text data out of JSON files | ||
/// | ||
/// From: https://andrewlock.net/creating-a-custom-xunit-theory-test-dataattribute-to-load-data-from-json-files/ | ||
/// </summary> | ||
public class JsonFileDataAttribute : DataAttribute | ||
{ | ||
private readonly string _filePath; | ||
private readonly string _propertyName; | ||
|
||
/// <summary> | ||
/// Load data from a JSON file as the data source for a theory | ||
/// </summary> | ||
/// <param name="filePath">The absolute or relative path to the JSON file to load</param> | ||
public JsonFileDataAttribute(string filePath) | ||
: this(filePath, null) { } | ||
|
||
/// <summary> | ||
/// Load data from a JSON file as the data source for a theory | ||
/// </summary> | ||
/// <param name="filePath">The absolute or relative path to the JSON file to load</param> | ||
/// <param name="propertyName">The name of the property on the JSON file that contains the data for the test</param> | ||
public JsonFileDataAttribute(string filePath, string propertyName) | ||
{ | ||
_filePath = filePath; | ||
_propertyName = propertyName; | ||
} | ||
|
||
/// <inheritDoc /> | ||
public override IEnumerable<object[]> GetData(MethodInfo testMethod) | ||
{ | ||
if (testMethod == null) { throw new ArgumentNullException(nameof(testMethod)); } | ||
|
||
// Get the absolute path to the JSON file | ||
var path = Path.IsPathRooted(_filePath) | ||
? _filePath | ||
: Path.GetRelativePath(Directory.GetCurrentDirectory(), _filePath); | ||
|
||
if (!File.Exists(path)) | ||
{ | ||
throw new ArgumentException($"Could not find file at path: {path}"); | ||
} | ||
|
||
// Load the file | ||
var fileData = File.ReadAllText(_filePath); | ||
|
||
if (string.IsNullOrEmpty(_propertyName)) | ||
{ | ||
//whole file is the data | ||
return JsonConvert.DeserializeObject<List<object[]>>(fileData); | ||
} | ||
|
||
// Only use the specified property as the data | ||
var allData = JObject.Parse(fileData); | ||
var data = allData[_propertyName]; | ||
return data.ToObject<List<object[]>>(); | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
/// <summary> | ||
/// Static class holding some utility methods regarding object collections | ||
/// </summary> | ||
public static class Lists | ||
{ | ||
/// <summary> | ||
/// Initializes a new list full of objects initialized with their default constructor. | ||
/// </summary> | ||
/// <param name="count">Number of objects in the list.</param> | ||
/// <typeparam name="T">Type of object in the list.</typeparam> | ||
/// <returns></returns> | ||
public static List<T> RepeatedDefault<T>(int count) | ||
{ | ||
return Repeated(default(T), count); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new list full of objects initialized with their default constructor. | ||
/// </summary> | ||
/// <param name="value">Object to insert on every index of the list.</param> | ||
/// <param name="count">Number of objects in the list.</param> | ||
/// <typeparam name="T">Type of object in the list.</typeparam> | ||
/// <returns></returns> | ||
public static List<T> Repeated<T>(T value, int count) | ||
{ | ||
List<T> repeated = new List<T>(count); | ||
repeated.AddRange(Enumerable.Repeat(value, count)); | ||
return repeated; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.