Skip to content

Commit

Permalink
Merge branch 'release/v0.9.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Spatz committed Nov 5, 2014
2 parents de1fd27 + 22b78b9 commit a1d672f
Show file tree
Hide file tree
Showing 26 changed files with 464 additions and 76 deletions.
26 changes: 18 additions & 8 deletions GenericStl.Tests/AsciiStlReaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
using System.IO;
using System;
using System.IO;
using FluentAssertions;
using GenericStl.Tests.TestDataStructures;
using NUnit.Framework;

namespace GenericStl.Tests
{
[TestFixture]
public class AsciiStlReaderTests
public class AsciiStlReaderTests : StlReaderBaseTests<AsciiStlReader<Triangle, Vertex, Normal>>
{
[TestFixtureSetUp]
public void TestFixtureSetUp()
[SetUp]
public void SetUp()
{

_objectUnderTest = new AsciiStlReader<Triangle, Vertex, Normal>(TestDataStructureHelpers.CreateTriangle, TestDataStructureHelpers.CreateVertex, TestDataStructureHelpers.CreateNormal);
}

[SetUp]
public void SetUp()
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
_objectUnderTest = new AsciiStlReader<Triangle, Vertex, Normal>(TestHelpers.CreateTriangle, TestHelpers.CreateVertex, TestHelpers.CreateNormal);
}

private const string AsciiTestFile = @".\TestData\ascii_block.stl";
private AsciiStlReader<Triangle, Vertex, Normal> _objectUnderTest;

protected override AsciiStlReader<Triangle, Vertex, Normal> CreateReader(Func<Vertex, Vertex, Vertex, Normal, Triangle> createTriangle, Func<float, float, float, Vertex> createVertex, Func<float, float, float, Normal> createNormal)
{
return new AsciiStlReader<Triangle, Vertex, Normal>(createTriangle, createVertex, createNormal);
}

protected override AsciiStlReader<Triangle, Vertex, Normal> CreateReader(IDataStructureCreator<Triangle, Vertex, Normal> structureCreator)
{
return new AsciiStlReader<Triangle, Vertex, Normal>(structureCreator);
}

[Test]
public void ReadFile_WithAsciiBlockFile_ReturnsExpectedTriangles()
{
Expand Down
17 changes: 14 additions & 3 deletions GenericStl.Tests/AsciiStlWriterTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using ApprovalTests;
using ApprovalTests.Reporters;
using GenericStl.Tests.TestDataStructures;
Expand All @@ -8,16 +9,26 @@ namespace GenericStl.Tests
{
[TestFixture]
[UseReporter(typeof (NUnitReporter))]
public class AsciiStlWriterTests
public class AsciiStlWriterTests : StlWriterBaseTests<AsciiStlWriter<Triangle, Vertex, Normal>>
{
[SetUp]
public void SetUp()
{
_objectUnderTest = new AsciiStlWriter<Triangle, Vertex, Normal>(TestHelpers.ExtractTriangle, TestHelpers.ExtractVertex, TestHelpers.ExtractNormal);
_objectUnderTest = new AsciiStlWriter<Triangle, Vertex, Normal>(TestDataStructureHelpers.ExtractTriangle, TestDataStructureHelpers.ExtractVertex, TestDataStructureHelpers.ExtractNormal);
}

private AsciiStlWriter<Triangle, Vertex, Normal> _objectUnderTest;

protected override AsciiStlWriter<Triangle, Vertex, Normal> CreateWriter(Func<Triangle, Tuple<Vertex, Vertex, Vertex, Normal>> extractTriangle, Func<Vertex, Tuple<float, float, float>> extractVertex, Func<Normal, Tuple<float, float, float>> extractNormal)
{
return new AsciiStlWriter<Triangle, Vertex, Normal>(extractTriangle, extractVertex, extractNormal);
}

protected override AsciiStlWriter<Triangle, Vertex, Normal> CreateWriter(IDataStructureExtractor<Triangle, Vertex, Normal> extractor)
{
return new AsciiStlWriter<Triangle, Vertex, Normal>(extractor);
}

[Test]
public void WriteFile_WithBlock_ReturnsExpectedResult()
{
Expand Down
17 changes: 14 additions & 3 deletions GenericStl.Tests/BinaryStlReaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
using System.IO;
using System;
using System.IO;
using FluentAssertions;
using GenericStl.Tests.TestDataStructures;
using NUnit.Framework;

namespace GenericStl.Tests
{
[TestFixture]
public class BinaryStlReaderTests
public class BinaryStlReaderTests : StlReaderBaseTests<BinaryStlReader<Triangle, Vertex, Normal>>
{
[SetUp]
public void SetUp()
{
_objectUnderTest = new BinaryStlReader<Triangle, Vertex, Normal>(TestHelpers.CreateTriangle, TestHelpers.CreateVertex, TestHelpers.CreateNormal);
_objectUnderTest = new BinaryStlReader<Triangle, Vertex, Normal>(TestDataStructureHelpers.CreateTriangle, TestDataStructureHelpers.CreateVertex, TestDataStructureHelpers.CreateNormal);
}

private BinaryStlReader<Triangle, Vertex, Normal> _objectUnderTest;
private const string BinaryTestFile = @".\TestData\binary_block.stl";

protected override BinaryStlReader<Triangle, Vertex, Normal> CreateReader(Func<Vertex, Vertex, Vertex, Normal, Triangle> createTriangle, Func<float, float, float, Vertex> createVertex, Func<float, float, float, Normal> createNormal)
{
return new BinaryStlReader<Triangle, Vertex, Normal>(createTriangle, createVertex, createNormal);
}

protected override BinaryStlReader<Triangle, Vertex, Normal> CreateReader(IDataStructureCreator<Triangle, Vertex, Normal> structureCreator)
{
return new BinaryStlReader<Triangle, Vertex, Normal>(structureCreator);
}

[Test]
public void ReadFile_WithBinaryBlockStl_ReturnsExpectedTriangles()
{
Expand Down
23 changes: 13 additions & 10 deletions GenericStl.Tests/BinaryStlWriterTests.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
using System.IO;
using System;
using System.IO;
using ApprovalTests;
using ApprovalTests.Reporters;
using GenericStl.Tests.TestDataStructures;
using NUnit.Framework;


namespace GenericStl.Tests
{
[TestFixture]
[UseReporter(typeof(NUnitReporter))]
public class BinaryStlWriterTests
[UseReporter(typeof (NUnitReporter))]
public class BinaryStlWriterTests : StlWriterBaseTests<BinaryStlWriter<Triangle, Vertex, Normal>>
{
[SetUp]
public void SetUp()

protected override BinaryStlWriter<Triangle, Vertex, Normal> CreateWriter(Func<Triangle, Tuple<Vertex, Vertex, Vertex, Normal>> extractTriangle, Func<Vertex, Tuple<float, float, float>> extractVertex, Func<Normal, Tuple<float, float, float>> extractNormal)
{
_objectUnderTest = new BinaryStlWriter<Triangle, Vertex, Normal>(TestHelpers.ExtractTriangle, TestHelpers.ExtractVertex, TestHelpers.ExtractNormal);
return new BinaryStlWriter<Triangle, Vertex, Normal>(extractTriangle, extractVertex, extractNormal);
}

private BinaryStlWriter<Triangle, Vertex, Normal> _objectUnderTest;
protected override BinaryStlWriter<Triangle, Vertex, Normal> CreateWriter(IDataStructureExtractor<Triangle, Vertex, Normal> extractor)
{
return new BinaryStlWriter<Triangle, Vertex, Normal>(extractor);
}

[Test]
public void WriteFile_WithBlock_ReturnsExpectedResult()
{
var namer = Approvals.GetDefaultNamer();
var file = Path.Combine(namer.SourcePath, namer.Name + ".received.stl");
_objectUnderTest.WriteToFile(file, TestHelpers.BlockExpectedResult);
ObjectUnderTest.WriteToFile(file, TestHelpers.BlockExpectedResult);
Approvals.Verify(new FileInfo(file));
}

[Test]
public void Write_WithBlock_ReturnsExpectedResult()
{
var result = _objectUnderTest.Write(TestHelpers.BlockExpectedResult);
var result = ObjectUnderTest.Write(TestHelpers.BlockExpectedResult);
Approvals.VerifyBinaryFile(result, ".stl");
}
}
Expand Down
5 changes: 5 additions & 0 deletions GenericStl.Tests/GenericStl.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@
<ItemGroup>
<Compile Include="AsciiStlReaderTests.cs" />
<Compile Include="AsciiStlWriterTests.cs" />
<Compile Include="StlReaderBaseTests.cs" />
<Compile Include="StlReaderTests.cs" />
<Compile Include="StlWriterBaseTests.cs" />
<Compile Include="SymmetryTests.cs" />
<Compile Include="BinaryStlReaderTests.cs" />
<Compile Include="BinaryStlWriterTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestDataStructures\Creator.cs" />
<Compile Include="TestDataStructures\Extractor.cs" />
<Compile Include="TestDataStructures\TestDataStructureHelpers.cs" />
<Compile Include="TestDataStructures\Triangle.cs" />
<Compile Include="TestDataStructures\Normal.cs" />
<Compile Include="TestDataStructures\Vertex.cs" />
Expand Down
4 changes: 2 additions & 2 deletions GenericStl.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.9.1.0")]
[assembly: AssemblyFileVersion("0.9.1.0")]
53 changes: 53 additions & 0 deletions GenericStl.Tests/StlReaderBaseTests.cs
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);

}
}
2 changes: 1 addition & 1 deletion GenericStl.Tests/StlReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class StlReaderTests
[SetUp]
public void SetUp()
{
_objectUnderTest = new StlReader<Triangle, Vertex, Normal>(TestHelpers.CreateTriangle, TestHelpers.CreateVertex, TestHelpers.CreateNormal);
_objectUnderTest = new StlReader<Triangle, Vertex, Normal>(TestDataStructureHelpers.CreateTriangle, TestDataStructureHelpers.CreateVertex, TestDataStructureHelpers.CreateNormal);
}

public IEnumerable StlFiles
Expand Down
84 changes: 84 additions & 0 deletions GenericStl.Tests/StlWriterBaseTests.cs
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);
}
}
4 changes: 2 additions & 2 deletions GenericStl.Tests/SymmetryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static IEnumerable ReaderWriters
{
get
{
yield return new TestCaseData(new AsciiStlReader<Triangle, Vertex, Normal>(TestHelpers.CreateTriangle, TestHelpers.CreateVertex, TestHelpers.CreateNormal), new AsciiStlWriter<Triangle, Vertex, Normal>(TestHelpers.ExtractTriangle, TestHelpers.ExtractVertex, TestHelpers.ExtractNormal)).SetName("Ascii");
yield return new TestCaseData(new BinaryStlReader<Triangle, Vertex, Normal>(TestHelpers.CreateTriangle, TestHelpers.CreateVertex, TestHelpers.CreateNormal), new BinaryStlWriter<Triangle, Vertex, Normal>(TestHelpers.ExtractTriangle, TestHelpers.ExtractVertex, TestHelpers.ExtractNormal)).SetName("Binary");
yield return new TestCaseData(new AsciiStlReader<Triangle, Vertex, Normal>(TestDataStructureHelpers.CreateTriangle, TestDataStructureHelpers.CreateVertex, TestDataStructureHelpers.CreateNormal), new AsciiStlWriter<Triangle, Vertex, Normal>(TestDataStructureHelpers.ExtractTriangle, TestDataStructureHelpers.ExtractVertex, TestDataStructureHelpers.ExtractNormal)).SetName("Ascii");
yield return new TestCaseData(new BinaryStlReader<Triangle, Vertex, Normal>(TestDataStructureHelpers.CreateTriangle, TestDataStructureHelpers.CreateVertex, TestDataStructureHelpers.CreateNormal), new BinaryStlWriter<Triangle, Vertex, Normal>(TestDataStructureHelpers.ExtractTriangle, TestDataStructureHelpers.ExtractVertex, TestDataStructureHelpers.ExtractNormal)).SetName("Binary");
}
}

Expand Down
20 changes: 20 additions & 0 deletions GenericStl.Tests/TestDataStructures/Creator.cs
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);
}
}
}
Loading

0 comments on commit a1d672f

Please sign in to comment.