Skip to content

Commit e7d5539

Browse files
committed
Change matrix generator -- now it could generate zero matrices
1 parent 364651a commit e7d5539

2 files changed

Lines changed: 29 additions & 36 deletions

File tree

tests/GraphBLAS-sharp.Tests/Common.fs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,15 @@ module Generators =
3333
Gen.choose (1, size |> float |> sqrt |> int)
3434
|> Gen.three
3535

36-
// non-empty and nonzeroes exists
37-
let pairOfSparseMatricesGenerator (valuesGenerator: Gen<'a>) (zero: 'a) (isZero: 'a -> bool) =
38-
Gen.sized <| fun size ->
39-
let sparseGenerator =
40-
Gen.oneof [
41-
valuesGenerator
42-
Gen.constant zero
43-
]
44-
45-
gen {
46-
// let! (rowsA, colsA, colsB) = dimension3DGenerator
47-
let! (nrows, ncols) = dimension2DGenerator
48-
let! matrixA = sparseGenerator |> Gen.array2DOfDim (nrows, ncols)
49-
let! matrixB = sparseGenerator |> Gen.array2DOfDim (nrows, ncols)
50-
return (matrixA, matrixB)
51-
}
52-
|> Gen.filter (fun (matrixA, matrixB) -> matrixA.Length <> 0 && matrixB.Length <> 0)
53-
|> Gen.filter
54-
(fun (matrixA, matrixB) ->
55-
matrixA |> Seq.cast<'a> |> Seq.exists (not << isZero) &&
56-
matrixB |> Seq.cast<'a> |> Seq.exists (not << isZero)
57-
)
36+
// generate non-empty matrices
37+
let pairOfMatricesOfEqualSizeGenerator (valuesGenerator: Gen<'a>) =
38+
gen {
39+
let! (nrows, ncols) = dimension2DGenerator
40+
let! matrixA = valuesGenerator |> Gen.array2DOfDim (nrows, ncols)
41+
let! matrixB = valuesGenerator |> Gen.array2DOfDim (nrows, ncols)
42+
return (matrixA, matrixB)
43+
}
44+
|> Gen.filter (fun (matrixA, matrixB) -> matrixA.Length <> 0 && matrixB.Length <> 0)
5845

5946
module Utils =
6047
let rec cartesian listOfLists =

tests/GraphBLAS-sharp.Tests/OperationsTests/EWiseAddTests.fs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,30 @@ let testCases =
3838
}
3939
)
4040

41-
type PairOfSparseMatrices =
41+
type PairOfSparseMatricesOfEqualSize =
4242
static member IntType() =
43-
Arb.fromGen <| Generators.pairOfSparseMatricesGenerator
44-
Arb.generate<int>
45-
0
46-
((=) 0)
43+
Generators.pairOfMatricesOfEqualSizeGenerator (
44+
Gen.oneof [
45+
Arb.generate<int>
46+
Gen.constant 0
47+
]
48+
) |> Arb.fromGen
4749

4850
static member FloatType() =
49-
Arb.fromGen <| Generators.pairOfSparseMatricesGenerator
50-
(Arb.Default.NormalFloat() |> Arb.toGen |> Gen.map float)
51-
0.
52-
(fun x -> abs x < Accuracy.medium.absolute)
51+
Generators.pairOfMatricesOfEqualSizeGenerator (
52+
Gen.oneof [
53+
(Arb.Default.NormalFloat() |> Arb.toGen |> Gen.map float)
54+
Gen.constant 0.
55+
]
56+
) |> Arb.fromGen
5357

5458
static member BoolType() =
55-
Arb.fromGen <| Generators.pairOfSparseMatricesGenerator
56-
Arb.generate<bool>
57-
false
58-
((=) false)
59+
Generators.pairOfMatricesOfEqualSizeGenerator (
60+
Gen.oneof [
61+
Arb.generate<bool>
62+
Gen.constant false
63+
]
64+
) |> Arb.fromGen
5965

6066
let createMatrix<'a when 'a : struct and 'a : equality> matrixFormat args =
6167
match matrixFormat with
@@ -163,7 +169,7 @@ let checkCorrectnessGeneric<'a when 'a : struct and 'a : equality>
163169

164170
let config = {
165171
FsCheckConfig.defaultConfig with
166-
arbitrary = [typeof<PairOfSparseMatrices>]
172+
arbitrary = [typeof<PairOfSparseMatricesOfEqualSize>]
167173
startSize = 0
168174
maxTest = 10
169175
}

0 commit comments

Comments
 (0)