diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 5901633..14b0578 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -16,14 +16,8 @@ jobs: fetch-depth: 0 - uses: mlugg/setup-zig@v1 - - name: Testing (Linux & MacOS) - if: (startsWith(matrix.runs-on, 'ubuntu')) || (startsWith(matrix.runs-on, 'macos')) - run: sh runall.sh - - - name: Testing (Windows) - if: startsWith(matrix.runs-on, 'windows') - run: ./runall.cmd - + - name: Testing + run: zig run runall.zig lint: runs-on: ubuntu-latest diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e7bcd35..2b1e028 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,45 +13,66 @@ Every project is managed by the `build.zig` file. ├── README.md ├── build.zig ├── concurrency -│   └── threads -│   └── ThreadPool.zig +│ └── threads +│ └── ThreadPool.zig ├── dataStructures -│   ├── linkedList.zig -│   └── lruCache.zig +│ ├── doublyLinkedList.zig +│ ├── linkedList.zig +│ ├── lruCache.zig +│ ├── stack.zig +│ └── trie.zig +├── dynamicProgramming +│ ├── coinChange.zig +│ ├── editDistance.zig +│ ├── knapsack.zig +│ └── longestIncreasingSubsequence.zig +├── machine_learning +│ └── k_means_clustering.zig ├── math -│   ├── ceil.zig -│   ├── chineseRemainderTheorem.zig -│   ├── euclidianGreatestCommonDivisor.zig -│   ├── factorial.zig -│   ├── fibonacciRecursion.zig -│   ├── gcd.zig -│   └── primes.zig +│ ├── ceil.zig +│ ├── chineseRemainderTheorem.zig +│ ├── euclidianGreatestCommonDivisor.zig +│ ├── factorial.zig +│ ├── fibonacciRecursion.zig +│ ├── gcd.zig +│ └── primes.zig ├── runall.sh ├── search -│   ├── binarySearchTree.zig -│   └── redBlackTrees.zig +│ ├── binarySearchTree.zig +│ └── redBlackTrees.zig ├── sort -│   ├── bubbleSort.zig -│   ├── insertionSort.zig -│   ├── mergeSort.zig -│   ├── quickSort.zig -│   └── radixSort.zig +│ ├── bubbleSort.zig +│ ├── insertionSort.zig +│ ├── mergeSort.zig +│ ├── quickSort.zig +│ └── radixSort.zig +└── web + ├── http + │ ├── client.zig + │ └── server.zig + └── tls + └── X25519+Kyber768Draft00.zig ``` To add a new algorithm you only need to categorize and pass the exact location of the new file. e.g.: ```zig - // build.zig - // new algorithm - if (std.mem.eql(u8, op, "category/algorithm-name")) - build_algorithm(b, mode, target, "algorithm-src.zig", "foldername"); +// build.zig +// new algorithm +if (std.mem.eql(u8, op, "category/algorithm-name")) + buildAlgorithm(b, .{ + .optimize = optimize, + .target = target, + .name = "algorithm-src.zig", + .category = "category", + }); ``` to test add: -```bash -# runall.sh -$ZIG_TEST -Dalgorithm="category/algorithm-name" $StackTrace +```zig +# runall.zig +try runTest(allocator, "category/algorithm-name"); ``` -**Note:** Do not change or modify the files (`build.zig` & `runall.sh`) without first suggesting it to the maintainers (open/issue proposal). \ No newline at end of file +**Note:** Do not change or modify the files (`build.zig` & `runall.zig`) without first suggesting it to the maintainers (open/issue proposal). \ No newline at end of file diff --git a/build.zig b/build.zig index 9d04405..d7844a9 100644 --- a/build.zig +++ b/build.zig @@ -209,7 +209,7 @@ pub fn build(b: *std.Build) void { .category = "web/tls", }); // Machine Learning - if (std.mem.eql(u8, op, "machine_learning/k_means_clustering.zig")) + if (std.mem.eql(u8, op, "machine_learning/k_means_clustering")) buildAlgorithm(b, .{ .optimize = optimize, .target = target, diff --git a/runall.cmd b/runall.cmd deleted file mode 100644 index 262fccd..0000000 --- a/runall.cmd +++ /dev/null @@ -1,55 +0,0 @@ -@echo off - -set ZIG_TEST=zig build test - -rem -fsummary Print the build summary, even on success -rem -freference-trace Reference trace should be shown per compile error -set Args=--summary all -freference-trace - -rem Test all algorithms - -rem Math -%ZIG_TEST% -Dalgorithm=math/ceil %Args% -%ZIG_TEST% -Dalgorithm=math/crt %Args% -%ZIG_TEST% -Dalgorithm=math/primes %Args% -%ZIG_TEST% -Dalgorithm=math/fibonacci %Args% -%ZIG_TEST% -Dalgorithm=math/factorial %Args% -%ZIG_TEST% -Dalgorithm=math/euclidianGCDivisor %Args% -%ZIG_TEST% -Dalgorithm=math/gcd %Args% - -rem Data Structures -%ZIG_TEST% -Dalgorithm=ds/trie %Args% -%ZIG_TEST% -Dalgorithm=ds/linkedlist %Args% -%ZIG_TEST% -Dalgorithm=ds/doublylinkedlist %Args% -%ZIG_TEST% -Dalgorithm=ds/lrucache %Args% -%ZIG_TEST% -Dalgorithm=ds/stack %Args% - -rem Dynamic Programming -%ZIG_TEST% -Dalgorithm=dp/coinChange %Args% -%ZIG_TEST% -Dalgorithm=dp/knapsack %Args% -%ZIG_TEST% -Dalgorithm=dp/longestIncreasingSubsequence %Args% -%ZIG_TEST% -Dalgorithm=dp/editDistance %Args% - -rem Sort -%ZIG_TEST% -Dalgorithm=sort/quicksort %Args% -%ZIG_TEST% -Dalgorithm=sort/bubblesort %Args% -%ZIG_TEST% -Dalgorithm=sort/radixsort %Args% -%ZIG_TEST% -Dalgorithm=sort/mergesort %Args% -%ZIG_TEST% -Dalgorithm=sort/insertsort %Args% - -rem Search -%ZIG_TEST% -Dalgorithm=search/bSearchTree %Args% -%ZIG_TEST% -Dalgorithm=search/rb %Args% - -rem Threads -%ZIG_TEST% -Dalgorithm=threads/threadpool %Args% - -rem Web -%ZIG_TEST% -Dalgorithm=web/httpClient %Args% -%ZIG_TEST% -Dalgorithm=web/httpServer %Args% -%ZIG_TEST% -Dalgorithm=web/tls1_3 %Args% - -rem Machine Learning -%ZIG_TEST% -Dalgorithm=machine_learning/k_means_clustering.zig %Args% - -rem Add more... diff --git a/runall.sh b/runall.sh deleted file mode 100755 index 552af45..0000000 --- a/runall.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env bash - -ZIG_TEST='zig build test' - -# -fsummary Print the build summary, even on success -# -freference-trace Reference trace should be shown per compile error -Args='--summary all -freference-trace' - -## Test all algorithms - -# Math -$ZIG_TEST -Dalgorithm=math/ceil $Args -$ZIG_TEST -Dalgorithm=math/crt $Args -$ZIG_TEST -Dalgorithm=math/primes $Args -$ZIG_TEST -Dalgorithm=math/fibonacci $Args -$ZIG_TEST -Dalgorithm=math/factorial $Args -$ZIG_TEST -Dalgorithm=math/euclidianGCDivisor $Args -$ZIG_TEST -Dalgorithm=math/gcd $Args - -# Data Structures -$ZIG_TEST -Dalgorithm=ds/trie $Args -$ZIG_TEST -Dalgorithm=ds/linkedlist $Args -$ZIG_TEST -Dalgorithm=ds/doublylinkedlist $Args -$ZIG_TEST -Dalgorithm=ds/lrucache $Args -$ZIG_TEST -Dalgorithm=ds/stack $Args - -# Dynamic Programming -$ZIG_TEST -Dalgorithm=dp/coinChange $Args -$ZIG_TEST -Dalgorithm=dp/knapsack $Args -$ZIG_TEST -Dalgorithm=dp/longestIncreasingSubsequence $Args -$ZIG_TEST -Dalgorithm=dp/editDistance $Args - -## Sort -$ZIG_TEST -Dalgorithm=sort/quicksort $Args -$ZIG_TEST -Dalgorithm=sort/bubblesort $Args -$ZIG_TEST -Dalgorithm=sort/radixsort $Args -$ZIG_TEST -Dalgorithm=sort/mergesort $Args -$ZIG_TEST -Dalgorithm=sort/insertsort $Args - -## Search -$ZIG_TEST -Dalgorithm=search/bSearchTree $Args -$ZIG_TEST -Dalgorithm=search/rb $Args - -## Threads -$ZIG_TEST -Dalgorithm=threads/threadpool $Args - -## Web -$ZIG_TEST -Dalgorithm=web/httpClient $Args -$ZIG_TEST -Dalgorithm=web/httpServer $Args -$ZIG_TEST -Dalgorithm=web/tls1_3 $Args - -## Machine Learning -$ZIG_TEST -Dalgorithm=machine_learning/k_means_clustering.zig $Args -## Add more... diff --git a/runall.zig b/runall.zig new file mode 100644 index 0000000..935a1c2 --- /dev/null +++ b/runall.zig @@ -0,0 +1,71 @@ +const std = @import("std"); + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + const allocator = gpa.allocator(); + + // Math algorithms + try runTest(allocator, "math/ceil"); + try runTest(allocator, "math/crt"); + try runTest(allocator, "math/primes"); + try runTest(allocator, "math/fibonacci"); + try runTest(allocator, "math/factorial"); + try runTest(allocator, "math/euclidianGCDivisor"); + try runTest(allocator, "math/gcd"); + + // Data Structures + try runTest(allocator, "ds/trie"); + try runTest(allocator, "ds/linkedlist"); + try runTest(allocator, "ds/doublylinkedlist"); + try runTest(allocator, "ds/lrucache"); + try runTest(allocator, "ds/stack"); + + // Dynamic Programming + try runTest(allocator, "dp/coinChange"); + try runTest(allocator, "dp/knapsack"); + try runTest(allocator, "dp/longestIncreasingSubsequence"); + try runTest(allocator, "dp/editDistance"); + + // Sort + try runTest(allocator, "sort/quicksort"); + try runTest(allocator, "sort/bubblesort"); + try runTest(allocator, "sort/radixsort"); + try runTest(allocator, "sort/mergesort"); + try runTest(allocator, "sort/insertsort"); + + // Search + try runTest(allocator, "search/bSearchTree"); + try runTest(allocator, "search/rb"); + + // Threads + try runTest(allocator, "threads/threadpool"); + + // Web + try runTest(allocator, "web/httpClient"); + try runTest(allocator, "web/httpServer"); + try runTest(allocator, "web/tls1_3"); + + // Machine Learning + try runTest(allocator, "machine_learning/k_means_clustering"); +} + +fn runTest(allocator: std.mem.Allocator, comptime algorithm: []const u8) !void { + var child = std.process.Child.init(&[_][]const u8{ + "zig", + "build", + "test", + "-Dalgorithm=" ++ algorithm, + } ++ args, allocator); + + child.stderr = std.io.getStdErr(); + child.stdout = std.io.getStdOut(); + + _ = try child.spawnAndWait(); +} + +const args = [_][]const u8{ + "--summary", + "all", + "-freference-trace", +};