Fix workflow (#16)

This commit is contained in:
Patrick Stevens
2024-07-14 13:06:41 +01:00
committed by GitHub
parent b2df9db225
commit 38bb5c94f2
14 changed files with 286 additions and 476 deletions

View File

@@ -1,33 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="TestUtils.fs" />
<Compile Include="TestPpmOutput.fs" />
<Compile Include="TestRay.fs" />
<Compile Include="TestSphereIntersection.fs" />
<EmbeddedResource Include="PpmOutputExample.txt" />
<Compile Include="TestPixel.fs" />
<Compile Include="TestPlane.fs" />
<Compile Include="TestSphere.fs" />
<Compile Include="TestRandom.fs" />
<Compile Include="TestBoundingBox.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FsCheck" Version="3.0.0-alpha5" />
<PackageReference Include="FsUnit" Version="4.0.4" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0-beta.1" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="13.2.28" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RayTracing\RayTracing.fsproj" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="TestUtils.fs" />
<Compile Include="TestPpmOutput.fs" />
<Compile Include="TestRay.fs" />
<Compile Include="TestSphereIntersection.fs" />
<EmbeddedResource Include="PpmOutputExample.txt" />
<Compile Include="TestPixel.fs" />
<Compile Include="TestPlane.fs" />
<Compile Include="TestSphere.fs" />
<Compile Include="TestRandom.fs" />
<Compile Include="TestBoundingBox.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FsCheck" Version="3.0.0-rc3" />
<PackageReference Include="FsUnit" Version="6.0.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="13.2.28" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RayTracing\RayTracing.fsproj" />
</ItemGroup>
</Project>

View File

@@ -2,6 +2,7 @@ namespace RayTracing.Test
open NUnit.Framework
open FsCheck
open FsCheck.FSharp
open RayTracing
[<TestFixture>]

View File

@@ -3,6 +3,7 @@ namespace RayTracing.Test
open RayTracing
open NUnit.Framework
open FsCheck
open FsCheck.FSharp
[<TestFixture>]
module TestRay =
@@ -32,7 +33,10 @@ module TestRay =
Vector.equal actual expected
let gen : Gen<float> = Arb.generate<NormalFloat> |> Gen.map NormalFloat.op_Explicit
let gen : Gen<float> =
ArbMap.defaults
|> ArbMap.generate<NormalFloat>
|> Gen.map NormalFloat.op_Explicit
let gen = Gen.zip (Gen.zip (Gen.two (Gen.three gen)) TestUtils.unitVectorGen) gen
@@ -49,7 +53,13 @@ module TestRay =
property
|> Prop.forAll (
Arb.fromGen (Gen.zip TestUtils.rayGen (Arb.generate<NormalFloat> |> Gen.map NormalFloat.op_Explicit))
Arb.fromGen (
Gen.zip
TestUtils.rayGen
(ArbMap.defaults
|> ArbMap.generate<NormalFloat>
|> Gen.map NormalFloat.op_Explicit)
)
)
|> Check.QuickThrowOnFailure
@@ -61,6 +71,12 @@ module TestRay =
property
|> Prop.forAll (
Arb.fromGen (Gen.zip TestUtils.rayGen (Arb.generate<NormalFloat> |> Gen.map NormalFloat.op_Explicit))
Arb.fromGen (
Gen.zip
TestUtils.rayGen
(ArbMap.defaults
|> ArbMap.generate<NormalFloat>
|> Gen.map NormalFloat.op_Explicit)
)
)
|> Check.QuickThrowOnFailure

View File

@@ -4,6 +4,7 @@ open System
open RayTracing
open NUnit.Framework
open FsCheck
open FsCheck.FSharp
open FsUnitTyped
[<TestFixture>]
@@ -23,9 +24,21 @@ module TestSphere =
let gen : Gen<Point * float * Point> =
gen {
let! centre = TestUtils.pointGen
let! radius = Arb.generate<NormalFloat> |> Gen.map NormalFloat.op_Explicit
let! theta = Arb.generate<NormalFloat> |> Gen.map NormalFloat.op_Explicit
let! phi = Arb.generate<NormalFloat> |> Gen.map NormalFloat.op_Explicit
let! radius =
ArbMap.defaults
|> ArbMap.generate<NormalFloat>
|> Gen.map NormalFloat.op_Explicit
let! theta =
ArbMap.defaults
|> ArbMap.generate<NormalFloat>
|> Gen.map NormalFloat.op_Explicit
let! phi =
ArbMap.defaults
|> ArbMap.generate<NormalFloat>
|> Gen.map NormalFloat.op_Explicit
let surfacePoint =
Point.make (radius * cos phi * sin theta) (radius * sin phi * sin theta) (radius * cos theta)
@@ -161,16 +174,17 @@ module TestSphere =
result
let boundedFloat upperBound =
Arb.generate<NormalFloat>
ArbMap.defaults
|> ArbMap.generate<NormalFloat>
|> Gen.map (fun i -> abs i.Get)
|> Gen.filter (fun i -> i <= upperBound)
let arb =
gen {
let! oX = Arb.generate<NormalFloat>
let! oY = Arb.generate<NormalFloat>
let! oZ = Arb.generate<NormalFloat>
let! radius = Arb.generate<NormalFloat>
let! oX = ArbMap.defaults |> ArbMap.generate<NormalFloat>
let! oY = ArbMap.defaults |> ArbMap.generate<NormalFloat>
let! oZ = ArbMap.defaults |> ArbMap.generate<NormalFloat>
let! radius = ArbMap.defaults |> ArbMap.generate<NormalFloat>
let! theta = boundedFloat 1.0
let! phi = boundedFloat 1.0
return ((oX, oY, oZ), radius), theta, phi

View File

@@ -2,6 +2,7 @@ namespace RayTracing.Test
open NUnit.Framework
open FsCheck
open FsCheck.FSharp
open FsUnitTyped
open RayTracing
@@ -12,7 +13,7 @@ module TestSphereIntersection =
let sphere : Gen<Sphere> =
gen {
let! origin = TestUtils.pointGen
let! radius = Arb.generate<NormalFloat>
let! radius = ArbMap.defaults |> ArbMap.generate<NormalFloat>
return Sphere.make (SphereStyle.LightSource (Texture.Colour Colour.White)) origin radius.Get
}

View File

@@ -4,13 +4,12 @@ open RayTracing
open System.IO
open System.Reflection
open FsCheck
open FsCheck.FSharp
[<RequireQualifiedAccess>]
module TestUtils =
type Dummy =
class
end
type Dummy = class end
let getEmbeddedResource (filename : string) : string =
let filename =
@@ -23,14 +22,17 @@ module TestUtils =
use reader = new StreamReader (stream)
reader.ReadToEnd().Replace ("\r\n", "\n")
let floatGen = Arb.generate<NormalFloat> |> Gen.map NormalFloat.op_Explicit
let floatGen =
ArbMap.defaults
|> ArbMap.generate<NormalFloat>
|> Gen.map NormalFloat.op_Explicit
let pointGen =
Gen.three Arb.generate<NormalFloat>
Gen.three (ArbMap.defaults |> ArbMap.generate<NormalFloat>)
|> Gen.map (fun (i, j, k) -> Point.make i.Get j.Get k.Get)
let vectorGen =
Gen.three Arb.generate<NormalFloat>
Gen.three (ArbMap.defaults |> ArbMap.generate<NormalFloat>)
|> Gen.map (fun (i, j, k) -> Vector.make i.Get j.Get k.Get)
let unitVectorGen =