Skip to content

Commit 4f2b965

Browse files
committed
refactor: map tests
1 parent f223b97 commit 4f2b965

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

  • tests/GraphBLAS-sharp.Tests/Matrix

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,28 @@ let correctnessGenericTest
8787
| ex when ex.Message = "InvalidBufferSize" -> ()
8888
| ex -> raise ex
8989

90-
let createTestMap case (zero: 'a) op isEqual opQ map =
90+
let createTestMap case (zero: 'a) (constant: 'a) binOp isEqual opQ =
9191
let getCorrectnessTestName = getCorrectnessTestName case
9292

9393
let context = case.TestContext.ClContext
9494
let q = case.TestContext.Queue
9595

96-
let map = map context opQ wgSize
96+
let unaryOp = binOp constant
97+
let unaryOpQ = opQ zero constant
98+
99+
let map = Matrix.map context unaryOpQ wgSize
97100

98101
let toCOO = Matrix.toCOO context wgSize
99102

100103
case
101-
|> correctnessGenericTest zero op map toCOO isEqual q
104+
|> correctnessGenericTest zero unaryOp map toCOO isEqual q
102105
|> testPropertyWithConfig config (getCorrectnessTestName $"{typeof<'a>}")
103106

104107
let testFixturesMapNot case =
105108
[ let q = case.TestContext.Queue
106109
q.Error.Add(fun e -> failwithf "%A" e)
107110

108-
createTestMap case false not (=) ArithmeticOperations.notQ Matrix.map ]
111+
createTestMap case false true (fun _ -> not) (=) (fun _ _ -> ArithmeticOperations.notQ) ]
109112

110113
let notTests =
111114
operationGPUTests "Backend.Matrix.map not tests" testFixturesMapNot
@@ -116,11 +119,11 @@ let testFixturesMapAdd case =
116119
q.Error.Add(fun e -> failwithf "%A" e)
117120

118121
if Utils.isFloat64Available context.ClDevice then
119-
createTestMap case 0.0 ((+) 10.0) Utils.floatIsEqual (ArithmeticOperations.addLeftConst 0.0 10.0) Matrix.map
122+
createTestMap case 0.0 10.0 (+) Utils.floatIsEqual ArithmeticOperations.addLeftConst
120123

121-
createTestMap case 0.0f ((+) 10.0f) Utils.float32IsEqual (ArithmeticOperations.addLeftConst 0.0f 10.0f) Matrix.map
124+
createTestMap case 0.0f 10.0f (+) Utils.float32IsEqual ArithmeticOperations.addLeftConst
122125

123-
createTestMap case 0uy ((+) 10uy) (=) (ArithmeticOperations.addLeftConst 0uy 10uy) Matrix.map ]
126+
createTestMap case 0uy 10uy (+) (=) ArithmeticOperations.addLeftConst ]
124127

125128
let addTests =
126129
operationGPUTests "Backend.Matrix.map add tests" testFixturesMapAdd
@@ -131,11 +134,11 @@ let testFixturesMapMul case =
131134
q.Error.Add(fun e -> failwithf "%A" e)
132135

133136
if Utils.isFloat64Available context.ClDevice then
134-
createTestMap case 0.0 ((*) 10.0) Utils.floatIsEqual (ArithmeticOperations.mulLeftConst 0.0 10.0) Matrix.map
137+
createTestMap case 0.0 10.0 (*) Utils.floatIsEqual ArithmeticOperations.mulLeftConst
135138

136-
createTestMap case 0.0f ((*) 10.0f) Utils.float32IsEqual (ArithmeticOperations.mulLeftConst 0.0f 10.0f) Matrix.map
139+
createTestMap case 0.0f 10.0f (*) Utils.float32IsEqual ArithmeticOperations.mulLeftConst
137140

138-
createTestMap case 0uy ((*) 10uy) (=) (ArithmeticOperations.mulLeftConst 0uy 10uy) Matrix.map ]
141+
createTestMap case 0uy 10uy (*) (=) ArithmeticOperations.mulLeftConst ]
139142

140143
let mulTests =
141144
operationGPUTests "Backend.Matrix.map mul tests" testFixturesMapMul

0 commit comments

Comments
 (0)