Skip to content

Commit f97c143

Browse files
authored
update runall script (#26)
1 parent a9b508c commit f97c143

File tree

6 files changed

+121
-144
lines changed

6 files changed

+121
-144
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@ jobs:
1616
fetch-depth: 0
1717
- uses: mlugg/setup-zig@v1
1818

19-
- name: Testing (Linux & MacOS)
20-
if: (startsWith(matrix.runs-on, 'ubuntu')) || (startsWith(matrix.runs-on, 'macos'))
21-
run: sh runall.sh
22-
23-
- name: Testing (Windows)
24-
if: startsWith(matrix.runs-on, 'windows')
25-
run: ./runall.cmd
26-
19+
- name: Testing
20+
run: zig run runall.zig
2721

2822
lint:
2923
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,66 @@ Every project is managed by the `build.zig` file.
1313
├── README.md
1414
├── build.zig
1515
├── concurrency
16-
   └── threads
17-
   └── ThreadPool.zig
16+
└── threads
17+
└── ThreadPool.zig
1818
├── dataStructures
19-
│   ├── linkedList.zig
20-
│   └── lruCache.zig
19+
│ ├── doublyLinkedList.zig
20+
│ ├── linkedList.zig
21+
│ ├── lruCache.zig
22+
│ ├── stack.zig
23+
│ └── trie.zig
24+
├── dynamicProgramming
25+
│ ├── coinChange.zig
26+
│ ├── editDistance.zig
27+
│ ├── knapsack.zig
28+
│ └── longestIncreasingSubsequence.zig
29+
├── machine_learning
30+
│ └── k_means_clustering.zig
2131
├── math
22-
   ├── ceil.zig
23-
   ├── chineseRemainderTheorem.zig
24-
   ├── euclidianGreatestCommonDivisor.zig
25-
   ├── factorial.zig
26-
   ├── fibonacciRecursion.zig
27-
   ├── gcd.zig
28-
   └── primes.zig
32+
├── ceil.zig
33+
├── chineseRemainderTheorem.zig
34+
├── euclidianGreatestCommonDivisor.zig
35+
├── factorial.zig
36+
├── fibonacciRecursion.zig
37+
├── gcd.zig
38+
└── primes.zig
2939
├── runall.sh
3040
├── search
31-
   ├── binarySearchTree.zig
32-
   └── redBlackTrees.zig
41+
├── binarySearchTree.zig
42+
└── redBlackTrees.zig
3343
├── sort
34-
│   ├── bubbleSort.zig
35-
│   ├── insertionSort.zig
36-
│   ├── mergeSort.zig
37-
│   ├── quickSort.zig
38-
│   └── radixSort.zig
44+
│ ├── bubbleSort.zig
45+
│ ├── insertionSort.zig
46+
│ ├── mergeSort.zig
47+
│ ├── quickSort.zig
48+
│ └── radixSort.zig
49+
└── web
50+
├── http
51+
│ ├── client.zig
52+
│ └── server.zig
53+
└── tls
54+
└── X25519+Kyber768Draft00.zig
3955
```
4056

4157
To add a new algorithm you only need to categorize and pass the exact location of the new file.
4258

4359
e.g.:
4460
```zig
45-
// build.zig
46-
// new algorithm
47-
if (std.mem.eql(u8, op, "category/algorithm-name"))
48-
build_algorithm(b, mode, target, "algorithm-src.zig", "foldername");
61+
// build.zig
62+
// new algorithm
63+
if (std.mem.eql(u8, op, "category/algorithm-name"))
64+
buildAlgorithm(b, .{
65+
.optimize = optimize,
66+
.target = target,
67+
.name = "algorithm-src.zig",
68+
.category = "category",
69+
});
4970
```
5071
to test add:
5172

52-
```bash
53-
# runall.sh
54-
$ZIG_TEST -Dalgorithm="category/algorithm-name" $StackTrace
73+
```zig
74+
# runall.zig
75+
try runTest(allocator, "category/algorithm-name");
5576
```
5677

57-
**Note:** Do not change or modify the files (`build.zig` & `runall.sh`) without first suggesting it to the maintainers (open/issue proposal).
78+
**Note:** Do not change or modify the files (`build.zig` & `runall.zig`) without first suggesting it to the maintainers (open/issue proposal).

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub fn build(b: *std.Build) void {
209209
.category = "web/tls",
210210
});
211211
// Machine Learning
212-
if (std.mem.eql(u8, op, "machine_learning/k_means_clustering.zig"))
212+
if (std.mem.eql(u8, op, "machine_learning/k_means_clustering"))
213213
buildAlgorithm(b, .{
214214
.optimize = optimize,
215215
.target = target,

runall.cmd

Lines changed: 0 additions & 55 deletions
This file was deleted.

runall.sh

Lines changed: 0 additions & 54 deletions
This file was deleted.

runall.zig

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const std = @import("std");
2+
3+
pub fn main() !void {
4+
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
5+
defer _ = gpa.deinit();
6+
const allocator = gpa.allocator();
7+
8+
// Math algorithms
9+
try runTest(allocator, "math/ceil");
10+
try runTest(allocator, "math/crt");
11+
try runTest(allocator, "math/primes");
12+
try runTest(allocator, "math/fibonacci");
13+
try runTest(allocator, "math/factorial");
14+
try runTest(allocator, "math/euclidianGCDivisor");
15+
try runTest(allocator, "math/gcd");
16+
17+
// Data Structures
18+
try runTest(allocator, "ds/trie");
19+
try runTest(allocator, "ds/linkedlist");
20+
try runTest(allocator, "ds/doublylinkedlist");
21+
try runTest(allocator, "ds/lrucache");
22+
try runTest(allocator, "ds/stack");
23+
24+
// Dynamic Programming
25+
try runTest(allocator, "dp/coinChange");
26+
try runTest(allocator, "dp/knapsack");
27+
try runTest(allocator, "dp/longestIncreasingSubsequence");
28+
try runTest(allocator, "dp/editDistance");
29+
30+
// Sort
31+
try runTest(allocator, "sort/quicksort");
32+
try runTest(allocator, "sort/bubblesort");
33+
try runTest(allocator, "sort/radixsort");
34+
try runTest(allocator, "sort/mergesort");
35+
try runTest(allocator, "sort/insertsort");
36+
37+
// Search
38+
try runTest(allocator, "search/bSearchTree");
39+
try runTest(allocator, "search/rb");
40+
41+
// Threads
42+
try runTest(allocator, "threads/threadpool");
43+
44+
// Web
45+
try runTest(allocator, "web/httpClient");
46+
try runTest(allocator, "web/httpServer");
47+
try runTest(allocator, "web/tls1_3");
48+
49+
// Machine Learning
50+
try runTest(allocator, "machine_learning/k_means_clustering");
51+
}
52+
53+
fn runTest(allocator: std.mem.Allocator, comptime algorithm: []const u8) !void {
54+
var child = std.process.Child.init(&[_][]const u8{
55+
"zig",
56+
"build",
57+
"test",
58+
"-Dalgorithm=" ++ algorithm,
59+
} ++ args, allocator);
60+
61+
child.stderr = std.io.getStdErr();
62+
child.stdout = std.io.getStdOut();
63+
64+
_ = try child.spawnAndWait();
65+
}
66+
67+
const args = [_][]const u8{
68+
"--summary",
69+
"all",
70+
"-freference-trace",
71+
};

0 commit comments

Comments
 (0)