-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
464 additions
and
76 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
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
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
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,53 @@ | ||
using System; | ||
using FluentAssertions; | ||
using GenericStl.Tests.TestDataStructures; | ||
using NUnit.Framework; | ||
|
||
namespace GenericStl.Tests | ||
{ | ||
public abstract class StlReaderBaseTests<TStlReaderImplementation> where TStlReaderImplementation : StlReaderBase<Triangle, Vertex, Normal> | ||
{ | ||
protected readonly Func<Vertex, Vertex, Vertex, Normal, Triangle>[] CreateTriangleFuncData = new Func<Vertex, Vertex, Vertex, Normal, Triangle>[] | ||
{ | ||
null, | ||
TestDataStructureHelpers.CreateTriangle | ||
}; | ||
|
||
protected readonly Func<float, float, float, Vertex>[] CreateVertexFuncData = new Func<float, float, float, Vertex>[] | ||
{ | ||
null, | ||
TestDataStructureHelpers.CreateVertex | ||
}; | ||
|
||
protected readonly Func<float, float, float, Normal>[] CreateNormalFuncData = new Func<float, float, float, Normal>[] | ||
{ | ||
null, | ||
TestDataStructureHelpers.CreateNormal | ||
}; | ||
|
||
[Test] | ||
public void Ctor_WithNullCreator_ThrowsArgumentNullException() | ||
{ | ||
var call = new Action(() => CreateReader(null)); | ||
|
||
call.ShouldThrow<ArgumentNullException>(); | ||
} | ||
|
||
[Theory] | ||
public void Ctor_WithNullFunc_ThrowArgumentNullException( | ||
[ValueSource("CreateTriangleFuncData")]Func<Vertex, Vertex, Vertex, Normal, Triangle> createTriangle, | ||
[ValueSource("CreateVertexFuncData")]Func<float, float, float, Vertex> createVertex, | ||
[ValueSource("CreateNormalFuncData")]Func<float, float, float, Normal> createNormal) | ||
{ | ||
Assume.That(createTriangle == null || createVertex==null || createNormal == null); | ||
|
||
var call = new Action(() => CreateReader(createTriangle, createVertex, createNormal)); | ||
|
||
call.ShouldThrow<ArgumentNullException>(); | ||
} | ||
|
||
protected abstract TStlReaderImplementation CreateReader(Func<Vertex, Vertex, Vertex, Normal, Triangle> createTriangle, Func<float, float, float, Vertex> createVertex, Func<float, float, float, Normal> createNormal); | ||
protected abstract TStlReaderImplementation CreateReader(IDataStructureCreator<Triangle, Vertex, Normal> structureCreator); | ||
|
||
} | ||
} |
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,84 @@ | ||
using System; | ||
using System.IO; | ||
using FluentAssertions; | ||
using GenericStl.Tests.TestDataStructures; | ||
using NUnit.Framework; | ||
|
||
namespace GenericStl.Tests | ||
{ | ||
public abstract class StlWriterBaseTests<TWriterImpl> where TWriterImpl : StlWriterBase<Triangle, Vertex, Normal> | ||
{ | ||
protected readonly Func<Normal, Tuple<float, float, float>>[] ExtractNormalFuncData = new Func<Normal, Tuple<float, float, float>>[] | ||
{ | ||
null, | ||
TestDataStructureHelpers.ExtractNormal | ||
}; | ||
|
||
protected readonly Func<Triangle, Tuple<Vertex, Vertex, Vertex, Normal>>[] ExtractTriangleFuncData = new Func<Triangle, Tuple<Vertex, Vertex, Vertex, Normal>>[] | ||
{ | ||
null, | ||
TestDataStructureHelpers.ExtractTriangle | ||
}; | ||
|
||
protected readonly Func<Vertex, Tuple<float, float, float>>[] ExtractVertexFuncData = new Func<Vertex, Tuple<float, float, float>>[] | ||
{ | ||
null, | ||
TestDataStructureHelpers.ExtractVertex | ||
}; | ||
|
||
protected TWriterImpl ObjectUnderTest; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
ObjectUnderTest = CreateWriter(TestDataStructureHelpers.ExtractTriangle, TestDataStructureHelpers.ExtractVertex, TestDataStructureHelpers.ExtractNormal); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
ObjectUnderTest = null; | ||
} | ||
|
||
[Test] | ||
public void Ctor_WithNullCreator_ThrowsArgumentNullException() | ||
{ | ||
var call = new Action(() => CreateWriter(null)); | ||
|
||
call.ShouldThrow<ArgumentNullException>(); | ||
} | ||
|
||
[Theory] | ||
public void Ctor_WithNullFunc_ThrowArgumentNullException( | ||
[ValueSource("ExtractTriangleFuncData")] Func<Triangle, Tuple<Vertex, Vertex, Vertex, Normal>> extractTriangle, | ||
[ValueSource("ExtractVertexFuncData")] Func<Vertex, Tuple<float, float, float>> extractVertex, | ||
[ValueSource("ExtractNormalFuncData")] Func<Normal, Tuple<float, float, float>> extractNormal) | ||
{ | ||
Assume.That(extractTriangle == null || extractVertex == null || extractNormal == null); | ||
|
||
var call = new Action(() => CreateWriter(extractTriangle, extractVertex, extractNormal)); | ||
|
||
call.ShouldThrow<ArgumentNullException>(); | ||
} | ||
|
||
[Test] | ||
[ExpectedException(typeof (ArgumentNullException))] | ||
public void WriteToStream_WithNullStream_ThrowsArgumentNullException() | ||
{ | ||
ObjectUnderTest.WriteToStream(null, TestHelpers.BlockExpectedResult); | ||
} | ||
|
||
[Test] | ||
[ExpectedException(typeof (ArgumentNullException))] | ||
public void WriteToStream_WithNullTriangles_ThrowsArgumentNullException() | ||
{ | ||
using (var ms = new MemoryStream()) | ||
{ | ||
ObjectUnderTest.WriteToStream(ms, null); | ||
} | ||
} | ||
|
||
protected abstract TWriterImpl CreateWriter(Func<Triangle, Tuple<Vertex, Vertex, Vertex, Normal>> extractTriangle, Func<Vertex, Tuple<float, float, float>> extractVertex, Func<Normal, Tuple<float, float, float>> extractNormal); | ||
protected abstract TWriterImpl CreateWriter(IDataStructureExtractor<Triangle, Vertex, Normal> extractor); | ||
} | ||
} |
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,20 @@ | ||
namespace GenericStl.Tests.TestDataStructures | ||
{ | ||
public class Creator : IDataStructureCreator<Triangle, Vertex, Normal> | ||
{ | ||
public Triangle CreateTriangle(Vertex v1, Vertex v2, Vertex v3, Normal n) | ||
{ | ||
return TestDataStructureHelpers.CreateTriangle(v1, v2, v3, n); | ||
} | ||
|
||
public Normal CreateNormal(float x, float y, float z) | ||
{ | ||
return TestDataStructureHelpers.CreateNormal(x,y,z); | ||
} | ||
|
||
public Vertex CreateVertex(float x, float y, float z) | ||
{ | ||
return TestDataStructureHelpers.CreateVertex(x, y, z); | ||
} | ||
} | ||
} |
Oops, something went wrong.