Skip to content

Commit de5d998

Browse files
committed
refactor: namespaces in tests
1 parent 3261d08 commit de5d998

File tree

30 files changed

+1776
-1742
lines changed

30 files changed

+1776
-1742
lines changed
Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,66 @@
1-
module GraphBLAS.FSharp.Tests.Backend.Algorithms.BFS
1+
namespace GraphBLAS.FSharp.Tests.Backend.Algorithms
22

33
open Expecto
44
open GraphBLAS.FSharp.Backend
55
open GraphBLAS.FSharp.Backend.Common
66
open GraphBLAS.FSharp.Backend.Quotes
77
open GraphBLAS.FSharp.Tests
88
open GraphBLAS.FSharp.Tests.Context
9-
open GraphBLAS.FSharp.Tests.QuickGraph.Algorithms
10-
open GraphBLAS.FSharp.Tests.QuickGraph.CreateGraph
9+
open GraphBLAS.FSharp.Tests.Backend.QuickGraph.Algorithms
10+
open GraphBLAS.FSharp.Tests.Backend.QuickGraph.CreateGraph
1111
open GraphBLAS.FSharp.Backend.Objects
1212
open GraphBLAS.FSharp.Objects.ClVectorExtensions
1313
open GraphBLAS.FSharp.Objects
1414

15-
let testFixtures (testContext: TestContext) =
16-
[ let config = Utils.undirectedAlgoConfig
17-
let context = testContext.ClContext
18-
let queue = testContext.Queue
19-
let workGroupSize = Utils.defaultWorkGroupSize
15+
module BFS =
16+
let testFixtures (testContext: TestContext) =
17+
[ let config = Utils.undirectedAlgoConfig
18+
let context = testContext.ClContext
19+
let queue = testContext.Queue
20+
let workGroupSize = Utils.defaultWorkGroupSize
2021

21-
let testName =
22-
sprintf "Test on %A" testContext.ClContext
22+
let testName =
23+
sprintf "Test on %A" testContext.ClContext
2324

24-
let bfs =
25-
Algorithms.BFS.singleSource context ArithmeticOperations.intSum ArithmeticOperations.intMul workGroupSize
25+
let bfs =
26+
Algorithms.BFS.singleSource context ArithmeticOperations.intSum ArithmeticOperations.intMul workGroupSize
2627

27-
testPropertyWithConfig config testName
28-
<| fun (matrix: int [,]) ->
28+
testPropertyWithConfig config testName
29+
<| fun (matrix: int [,]) ->
2930

30-
let graph = undirectedFromArray2D matrix 0
31+
let graph = undirectedFromArray2D matrix 0
3132

32-
let largestComponent =
33-
ConnectedComponents.largestComponent graph
33+
let largestComponent =
34+
ConnectedComponents.largestComponent graph
3435

35-
if largestComponent.Length > 0 then
36-
let source = largestComponent.[0]
36+
if largestComponent.Length > 0 then
37+
let source = largestComponent.[0]
3738

38-
let expected =
39-
(snd (BFS.runUndirected graph source))
40-
|> Utils.createArrayFromDictionary (Array2D.length1 matrix) 0
39+
let expected =
40+
(snd (BFS.runUndirected graph source))
41+
|> Utils.createArrayFromDictionary (Array2D.length1 matrix) 0
4142

42-
let matrixHost =
43-
Utils.createMatrixFromArray2D CSR matrix ((=) 0)
43+
let matrixHost =
44+
Utils.createMatrixFromArray2D CSR matrix ((=) 0)
4445

45-
let matrix = matrixHost.ToDevice context
46+
let matrix = matrixHost.ToDevice context
4647

47-
match matrix with
48-
| ClMatrix.CSR mtx ->
49-
let res = bfs queue mtx source |> ClVector.Dense
48+
match matrix with
49+
| ClMatrix.CSR mtx ->
50+
let res = bfs queue mtx source |> ClVector.Dense
5051

51-
let resHost = res.ToHost queue
52+
let resHost = res.ToHost queue
5253

53-
(mtx :> IDeviceMemObject).Dispose queue
54-
res.Dispose queue
54+
(mtx :> IDeviceMemObject).Dispose queue
55+
res.Dispose queue
5556

56-
match resHost with
57-
| Vector.Dense resHost ->
58-
let actual = resHost |> Utils.unwrapOptionArray 0
57+
match resHost with
58+
| Vector.Dense resHost ->
59+
let actual = resHost |> Utils.unwrapOptionArray 0
5960

60-
Expect.sequenceEqual actual expected "Sequences must be equal"
61-
| _ -> failwith "Not implemented"
62-
| _ -> failwith "Not implemented" ]
61+
Expect.sequenceEqual actual expected "Sequences must be equal"
62+
| _ -> failwith "Not implemented"
63+
| _ -> failwith "Not implemented" ]
6364

64-
let tests =
65-
TestCases.gpuTests "Bfs tests" testFixtures
65+
let tests =
66+
TestCases.gpuTests "Bfs tests" testFixtures
Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module GraphBLAS.FSharp.Tests.Backend.Common.BitonicSort
1+
namespace GraphBLAS.FSharp.Tests.Backend.Common
22

33
open Expecto
44
open Expecto.Logging
@@ -8,78 +8,79 @@ open Brahma.FSharp
88
open GraphBLAS.FSharp.Tests
99
open GraphBLAS.FSharp.Tests.Context
1010

11-
let logger = Log.create "BitonicSort.Tests"
11+
module BitonicSort =
12+
let logger = Log.create "BitonicSort.Tests"
1213

13-
let context = defaultContext.ClContext
14+
let context = defaultContext.ClContext
1415

15-
let config =
16-
{ Utils.defaultConfig with
17-
endSize = 1000000 }
16+
let config =
17+
{ Utils.defaultConfig with
18+
endSize = 1000000 }
1819

19-
let wgSize = Utils.defaultWorkGroupSize
20+
let wgSize = Utils.defaultWorkGroupSize
2021

21-
let q = defaultContext.Queue
22+
let q = defaultContext.Queue
2223

23-
let makeTest sort (array: ('n * 'n * 'a) []) =
24-
if array.Length > 0 then
25-
let projection (row: 'n) (col: 'n) (_: 'a) = row, col
24+
let makeTest sort (array: ('n * 'n * 'a) []) =
25+
if array.Length > 0 then
26+
let projection (row: 'n) (col: 'n) (_: 'a) = row, col
2627

27-
logger.debug (
28-
eventX "Initial size is {size}"
29-
>> setField "size" $"%A{array.Length}"
30-
)
28+
logger.debug (
29+
eventX "Initial size is {size}"
30+
>> setField "size" $"%A{array.Length}"
31+
)
3132

32-
let rows, cols, vals = Array.unzip3 array
33+
let rows, cols, vals = Array.unzip3 array
3334

34-
use clRows = context.CreateClArray rows
35-
use clColumns = context.CreateClArray cols
36-
use clValues = context.CreateClArray vals
35+
use clRows = context.CreateClArray rows
36+
use clColumns = context.CreateClArray cols
37+
use clValues = context.CreateClArray vals
3738

38-
let actualRows, actualCols, actualValues =
39-
sort q clRows clColumns clValues
39+
let actualRows, actualCols, actualValues =
40+
sort q clRows clColumns clValues
4041

41-
let rows = Array.zeroCreate<'n> clRows.Length
42-
let columns = Array.zeroCreate<'n> clColumns.Length
43-
let values = Array.zeroCreate<'a> clValues.Length
42+
let rows = Array.zeroCreate<'n> clRows.Length
43+
let columns = Array.zeroCreate<'n> clColumns.Length
44+
let values = Array.zeroCreate<'a> clValues.Length
4445

45-
q.Post(Msg.CreateToHostMsg(clRows, rows))
46-
q.Post(Msg.CreateToHostMsg(clColumns, columns))
46+
q.Post(Msg.CreateToHostMsg(clRows, rows))
47+
q.Post(Msg.CreateToHostMsg(clColumns, columns))
4748

48-
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clValues, values, ch))
49-
|> ignore
49+
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clValues, values, ch))
50+
|> ignore
5051

51-
rows, columns, values
52+
rows, columns, values
5253

53-
let expectedRows, expectedCols, expectedValues =
54-
(rows, cols, vals)
55-
|||> Array.zip3
56-
|> Array.sortBy ((<|||) projection)
57-
|> Array.unzip3
54+
let expectedRows, expectedCols, expectedValues =
55+
(rows, cols, vals)
56+
|||> Array.zip3
57+
|> Array.sortBy ((<|||) projection)
58+
|> Array.unzip3
5859

59-
$"Row arrays should be equal. Actual is \n%A{actualRows}, expected \n%A{expectedRows}, input is \n%A{rows}"
60-
|> Utils.compareArrays (=) actualRows expectedRows
60+
$"Row arrays should be equal. Actual is \n%A{actualRows}, expected \n%A{expectedRows}, input is \n%A{rows}"
61+
|> Utils.compareArrays (=) actualRows expectedRows
6162

62-
$"Column arrays should be equal. Actual is \n%A{actualCols}, expected \n%A{expectedCols}, input is \n%A{cols}"
63-
|> Utils.compareArrays (=) actualCols expectedCols
63+
$"Column arrays should be equal. Actual is \n%A{actualCols}, expected \n%A{expectedCols}, input is \n%A{cols}"
64+
|> Utils.compareArrays (=) actualCols expectedCols
6465

65-
$"Value arrays should be equal. Actual is \n%A{actualValues}, expected \n%A{expectedValues}, input is \n%A{vals}"
66-
|> Utils.compareArrays (=) actualValues expectedValues
66+
$"Value arrays should be equal. Actual is \n%A{actualValues}, expected \n%A{expectedValues}, input is \n%A{vals}"
67+
|> Utils.compareArrays (=) actualValues expectedValues
6768

68-
let testFixtures<'a when 'a: equality> =
69-
BitonicSort.sortKeyValuesInplace<int, 'a> context wgSize
70-
|> makeTest
71-
|> testPropertyWithConfig config $"Correctness on %A{typeof<'a>}"
69+
let testFixtures<'a when 'a: equality> =
70+
BitonicSort.sortKeyValuesInplace<int, 'a> context wgSize
71+
|> makeTest
72+
|> testPropertyWithConfig config $"Correctness on %A{typeof<'a>}"
7273

73-
let tests =
74-
q.Error.Add(fun e -> failwithf "%A" e)
74+
let tests =
75+
q.Error.Add(fun e -> failwithf "%A" e)
7576

76-
[ testFixtures<int>
77+
[ testFixtures<int>
7778

78-
if Utils.isFloat64Available context.ClDevice then
79-
testFixtures<float>
79+
if Utils.isFloat64Available context.ClDevice then
80+
testFixtures<float>
8081

81-
testFixtures<float32>
82+
testFixtures<float32>
8283

83-
testFixtures<byte>
84-
testFixtures<bool> ]
85-
|> testList "Backend.Common.BitonicSort tests"
84+
testFixtures<byte>
85+
testFixtures<bool> ]
86+
|> testList "Backend.Common.BitonicSort tests"
Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Choose
1+
namespace GraphBLAS.FSharp.Tests.Backend.Common.ClArray
22

33
open GraphBLAS.FSharp.Backend.Common
44
open Expecto
@@ -8,50 +8,51 @@ open GraphBLAS.FSharp.Backend.Objects.ClContext
88
open Brahma.FSharp
99
open GraphBLAS.FSharp.Backend.Quotes
1010

11-
let workGroupSize = Utils.defaultWorkGroupSize
11+
module Choose =
12+
let workGroupSize = Utils.defaultWorkGroupSize
1213

13-
let config = Utils.defaultConfig
14+
let config = Utils.defaultConfig
1415

15-
let makeTest<'a, 'b> testContext choose mapFun isEqual (array: 'a []) =
16-
if array.Length > 0 then
17-
let context = testContext.ClContext
18-
let q = testContext.Queue
16+
let makeTest<'a, 'b> testContext choose mapFun isEqual (array: 'a []) =
17+
if array.Length > 0 then
18+
let context = testContext.ClContext
19+
let q = testContext.Queue
1920

20-
let clArray =
21-
context.CreateClArrayWithSpecificAllocationMode(DeviceOnly, array)
21+
let clArray =
22+
context.CreateClArrayWithSpecificAllocationMode(DeviceOnly, array)
2223

23-
let (clResult: ClArray<'b>) = choose q HostInterop clArray
24+
let (clResult: ClArray<'b>) = choose q HostInterop clArray
2425

25-
let hostResult = Array.zeroCreate clResult.Length
26+
let hostResult = Array.zeroCreate clResult.Length
2627

27-
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clResult, hostResult, ch))
28-
|> ignore
28+
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clResult, hostResult, ch))
29+
|> ignore
2930

30-
let expectedResult = Array.choose mapFun array
31+
let expectedResult = Array.choose mapFun array
3132

32-
"Result should be the same"
33-
|> Utils.compareArrays isEqual hostResult expectedResult
33+
"Result should be the same"
34+
|> Utils.compareArrays isEqual hostResult expectedResult
3435

35-
let createTest<'a, 'b> testContext mapFun mapFunQ isEqual =
36-
let context = testContext.ClContext
36+
let createTest<'a, 'b> testContext mapFun mapFunQ isEqual =
37+
let context = testContext.ClContext
3738

38-
let choose =
39-
ClArray.choose context workGroupSize mapFunQ
39+
let choose =
40+
ClArray.choose context workGroupSize mapFunQ
4041

41-
makeTest<'a, 'b> testContext choose mapFun isEqual
42-
|> testPropertyWithConfig config $"Correctness on %A{typeof<'a>} -> %A{typeof<'b>}"
42+
makeTest<'a, 'b> testContext choose mapFun isEqual
43+
|> testPropertyWithConfig config $"Correctness on %A{typeof<'a>} -> %A{typeof<'b>}"
4344

44-
let testFixtures testContext =
45-
let device = testContext.ClContext.ClDevice
45+
let testFixtures testContext =
46+
let device = testContext.ClContext.ClDevice
4647

47-
[ createTest<int option, int> testContext id Map.id (=)
48-
createTest<byte option, byte> testContext id Map.id (=)
49-
createTest<bool option, bool> testContext id Map.id (=)
48+
[ createTest<int option, int> testContext id Map.id (=)
49+
createTest<byte option, byte> testContext id Map.id (=)
50+
createTest<bool option, bool> testContext id Map.id (=)
5051

51-
if Utils.isFloat64Available device then
52-
createTest<float option, float> testContext id Map.id Utils.floatIsEqual
52+
if Utils.isFloat64Available device then
53+
createTest<float option, float> testContext id Map.id Utils.floatIsEqual
5354

54-
createTest<float32 option, float32> testContext id Map.id Utils.float32IsEqual ]
55+
createTest<float32 option, float32> testContext id Map.id Utils.float32IsEqual ]
5556

56-
let tests =
57-
TestCases.gpuTests "ClArray.choose id tests" testFixtures
57+
let tests =
58+
TestCases.gpuTests "ClArray.choose id tests" testFixtures

0 commit comments

Comments
 (0)