Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3 from AlanRynne/development
Browse files Browse the repository at this point in the history
Unit tests with xUnit and Travis-CI
  • Loading branch information
AlanRynne committed Jul 1, 2019
2 parents f5750b4 + 7c8cf52 commit 9c0f1eb
Show file tree
Hide file tree
Showing 58 changed files with 2,027 additions and 708 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -2,7 +2,9 @@ dist: trusty
sudo: required
language: csharp
mono: none
# Use net core 2.0.0 for compatibility reasons
dotnet: 2.0.0
script:
- dotnet restore
- dotnet build -c Release
- dotnet test AR_Lib.Tests
27 changes: 27 additions & 0 deletions .vscode/launch.json
@@ -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}"
}
]
}
36 changes: 36 additions & 0 deletions .vscode/tasks.json
@@ -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"
}
]
}
48 changes: 48 additions & 0 deletions AR_GeometryLibrary.sln
@@ -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
19 changes: 19 additions & 0 deletions AR_Lib.Tests/AR_Lib.Tests.csproj
@@ -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>
16 changes: 16 additions & 0 deletions AR_Lib.Tests/Geometry/Point3dData.cs
@@ -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();
}
}
18 changes: 18 additions & 0 deletions AR_Lib.Tests/Geometry/Point3dTests.cs
@@ -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);
}
}
}
7 changes: 7 additions & 0 deletions AR_Lib.Tests/Geometry/Vector3dTests.cs
@@ -0,0 +1,7 @@
namespace AR_Lib.Tests.Geometry
{
public class Vector3dTests
{

}
}
69 changes: 69 additions & 0 deletions AR_Lib.Tests/Utilities/JsonFileDataAttribute.cs
@@ -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.
33 changes: 33 additions & 0 deletions AR_Lib/Collections/Lists.cs
@@ -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;
}
}
29 changes: 17 additions & 12 deletions Collections/Matrix.cs → AR_Lib/Collections/Matrix.cs
@@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;

namespace AR_Lib
namespace AR_Lib.Collections
{
/// <summary>
/// 2-Dimensional generic matrix
/// </summary>
/// <typeparam name="T">Type of the objects in the matrix</typeparam>
public class Matrix<T>
{
/// Matrix Class
Expand Down Expand Up @@ -42,7 +46,7 @@ public class Matrix<T>
#region Constructors

/// <summary>
/// Generates a new empty square Matrix<T>
/// Generates a new empty square Matrix
/// </summary>
/// <param name="n">Size of the square Matrix</param>
public Matrix(int n)
Expand All @@ -51,7 +55,7 @@ public Matrix(int n)
}

/// <summary>
/// Generates an new empty Matrix<T> class of the specified size
/// Generates an new empty Matrix class of the specified size
/// </summary>
/// <param name="n">Column size</param>
/// <param name="m">Row size</param>
Expand All @@ -61,7 +65,7 @@ public Matrix(int n, int m)
}

/// <summary>
/// Generates a new Matrix<T> class out of a 2D array
/// Generates a new Matrix class out of a 2D array
/// </summary>
/// <param name="data">2D array of data</param>
public Matrix(T[,] data)
Expand All @@ -82,6 +86,8 @@ public Matrix(T[,] data)
public void FlipMatrix()
{
//TODO: Implement FlipMatrix()

throw new NotImplementedException();
}


Expand Down Expand Up @@ -138,11 +144,10 @@ public void IncrementMatrixSize(int columnIncrement, int rowIncrement)
/// <returns>List of all neighbour entities</returns>
public List<T> GetAllNeighboursAt(int column, int row)
{
///TODO: This is a hacked up implementation
///It provides the neighbours out of order (first contiguous, then corners)
//HACK: This is a hacked up implementation. It provides the neighbours out of order (first contiguous, then corners)

List<T> neighbours = GetContiguousNeighboursAt(column,row);
neighbours.AddRange(GetCornerNeighboursAt(column,row));
List<T> neighbours = GetContiguousNeighboursAt(column, row);
neighbours.AddRange(GetCornerNeighboursAt(column, row));

return neighbours;
}
Expand All @@ -156,7 +161,8 @@ public List<T> GetAllNeighboursAt(int column, int row)
public List<T> GetCornerNeighboursAt(int column, int row)
{
//TODO: Implement GetCornerNeighboursOfEntityAt()
return null;

throw new NotImplementedException();
}

/// <summary>
Expand All @@ -168,7 +174,8 @@ public List<T> GetCornerNeighboursAt(int column, int row)
public List<T> GetContiguousNeighboursAt(int column, int row)
{
//TODO: Implement GetContiguousNeighboursOfEntityAt()
return null;

throw new NotImplementedException();
}


Expand All @@ -182,11 +189,9 @@ public List<T> GetContiguousNeighboursAt(int column, int row)
/// It accepts smaller and bigger array outputs
/// Obtained from: https://stackoverflow.com/questions/6539571/how-to-resize-multidimensional-2d-array-in-c
/// </summary>
/// <param name="T">Class of the object in the array</param>
/// <param name="original">2D Array to resize</param>
/// <param name="newCoNum">Number of resulting columns in the array</param>
/// <param name="newRoNum">Number of resulting rows in the array</param>
/// <typeparam name="T"></typeparam>
private void ResizeMatrix(ref T[,] original, int newCoNum, int newRoNum)
{
var newArray = new T[newCoNum, newRoNum];
Expand Down

0 comments on commit 9c0f1eb

Please sign in to comment.