Skip to content

Commit 269806a

Browse files
committed
refactor: createTest in tests
1 parent 25b14d7 commit 269806a

12 files changed

Lines changed: 309 additions & 925 deletions

File tree

tests/GraphBLAS-sharp.Tests/Common/Exists.fs

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -44,56 +44,26 @@ let correctnessGenericTest<'a when 'a: struct and 'a: equality> isZero exists (a
4444
$"The results should be the same, vector : {vector}"
4545
|> Expect.equal result (Array.exists (not << isZero) array)
4646

47-
let testFixtures =
48-
49-
let getCorrectnessTestName datatype =
50-
sprintf "Correctness on %s, %A" datatype Dense
51-
52-
[ let exists =
53-
ClArray.exists context wgSize Predicates.isSome
54-
55-
correctnessGenericTest<int> ((=) 0) exists
56-
|> testPropertyWithConfig config (getCorrectnessTestName "int")
47+
let createTest<'a when 'a: struct and 'a: equality> isEqual zero =
48+
let exists =
49+
ClArray.exists context wgSize Predicates.isSome
5750

58-
correctnessGenericTest<int> ((=) 0) exists (Array.create 1000 0)
59-
|> testPropertyWithConfig config (getCorrectnessTestName "int zeros")
51+
[ correctnessGenericTest<'a> (isEqual zero) exists
52+
|> testPropertyWithConfig config "FSCheck data"
6053

61-
let exists =
62-
ClArray.exists context wgSize Predicates.isSome
54+
correctnessGenericTest<'a> (isEqual zero) exists (Array.create 1000 zero)
55+
|> testPropertyWithConfig config "Zeros" ]
56+
|> testList $"Correctness on %A{typeof<'a>}"
6357

64-
correctnessGenericTest<byte> ((=) 0uy) exists
65-
|> testPropertyWithConfig config (getCorrectnessTestName "byte")
66-
67-
correctnessGenericTest<byte> ((=) 0uy) exists (Array.create 1000 0uy)
68-
|> testPropertyWithConfig config (getCorrectnessTestName "byte zeros")
58+
let testFixtures =
59+
[ createTest<int> (=) 0
60+
createTest<byte> (=) 0uy
6961

7062
if Utils.isFloat64Available context.ClDevice then
71-
let exists =
72-
ClArray.exists context wgSize Predicates.isSome
73-
74-
correctnessGenericTest<float> ((=) 0.0) exists
75-
|> testPropertyWithConfig config (getCorrectnessTestName "float")
76-
77-
correctnessGenericTest<float> ((=) 0.0) exists (Array.create 1000 0.0)
78-
|> testPropertyWithConfig config (getCorrectnessTestName "float zeros")
79-
80-
let exists =
81-
ClArray.exists context wgSize Predicates.isSome
82-
83-
correctnessGenericTest<float32> ((=) 0.0f) exists
84-
|> testPropertyWithConfig config (getCorrectnessTestName "float32")
85-
86-
correctnessGenericTest<float32> ((=) 0.0f) exists (Array.create 1000 0.0f)
87-
|> testPropertyWithConfig config (getCorrectnessTestName "float32 zeros")
88-
89-
let exists =
90-
ClArray.exists context wgSize Predicates.isSome
91-
92-
correctnessGenericTest<bool> ((=) false) exists
93-
|> testPropertyWithConfig config (getCorrectnessTestName "bool")
63+
createTest Utils.floatIsEqual 0.0
9464

95-
correctnessGenericTest<bool> ((=) false) exists (Array.create 1000 false)
96-
|> testPropertyWithConfig config (getCorrectnessTestName "bool zeros") ]
65+
createTest<float32> Utils.float32IsEqual 0.0f
66+
createTest<bool> (=) false ]
9767

9868
let tests =
9969
testList "Backend.Vector.containsNonZero tests" testFixtures

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,16 @@ module Utils =
877877
| _ -> false)
878878
context.DeviceExtensions
879879

880+
let transpose2DArray array =
881+
let result =
882+
Array2D.zeroCreate (Array2D.length2 array) (Array2D.length1 array)
883+
884+
for i in 0 .. Array2D.length1 result - 1 do
885+
for j in 0 .. Array2D.length2 result - 1 do
886+
result.[i, j] <- array.[j, i]
887+
888+
result
889+
880890
module Context =
881891
type TestContext =
882892
{ ClContext: ClContext

tests/GraphBLAS-sharp.Tests/Matrix/Convert.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let makeTest context q formatFrom formatTo convertFun isZero (array: 'a [,]) =
4343

4444
let testFixtures formatTo =
4545
let getCorrectnessTestName datatype formatFrom =
46-
sprintf "Correctness on %s, %A to %A" datatype formatFrom formatTo
46+
$"Correctness on %s{datatype}, %A{formatFrom} to %A{formatTo}"
4747

4848
let context = defaultContext.ClContext
4949
let q = defaultContext.Queue

0 commit comments

Comments
 (0)