From a215e1e5fb7e4a4f2817476f935ab670b4d80b00 Mon Sep 17 00:00:00 2001 From: John Collins Date: Thu, 4 Apr 2024 00:50:23 -0700 Subject: [PATCH 1/6] Create pipeline --- .github/workflows/test.yaml | 32 ++++++++++++++ deps.edn | 6 ++- src/main/plexus/core.clj | 10 ++--- src/test/plexus/core_test.clj | 79 ----------------------------------- 4 files changed, 42 insertions(+), 85 deletions(-) create mode 100644 .github/workflows/test.yaml delete mode 100644 src/test/plexus/core_test.clj diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..05e1610 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,32 @@ +name: Clojure Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'temurin' + + - name: Cache Clojure Dependencies + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/deps.edn') }} + restore-keys: | + ${{ runner.os }}-m2 + + - name: Run tests + run: clojure -M:dev:test diff --git a/deps.edn b/deps.edn index 0b4a40a..988d646 100644 --- a/deps.edn +++ b/deps.edn @@ -2,7 +2,6 @@ :deps {net.mikera/core.matrix {:mvn/version "0.62.0"} ;; org.clojars.cartesiantheatrics/clj-manifold3d {:local/root "../clj-manifold3d"} org.clojars.cartesiantheatrics/clj-manifold3d {:mvn/version "0.0.18"} - camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"} net.mikera/vectorz-clj {:mvn/version "0.48.0"} metosin/malli {:mvn/version "0.11.0"} scad-clj/scad-clj {:mvn/version "0.5.3"}} @@ -11,6 +10,11 @@ {:extra-deps {org.clojars.cartesiantheatrics/manifold3d$linux-x86_64 {:mvn/version "1.0.77"}}} + :test {:extra-paths ["test/main"] + :extra-deps {lambdaisland/kaocha {:mvn/version "1.88.1376"} + org.clojure/clojure {:mvn/version "1.11.2"}} + :main-opts ["-m" "kaocha.runner"]} + :deploy {:extra-paths ["build"] :extra-deps {badigeon/badigeon {:mvn/version "1.7"} diff --git a/src/main/plexus/core.clj b/src/main/plexus/core.clj index c30756d..6c7acfc 100644 --- a/src/main/plexus/core.clj +++ b/src/main/plexus/core.clj @@ -2,12 +2,12 @@ (:refer-clojure :exclude [set]) (:require [clojure.java.io :as io] - [plexus.utils :as u] [plexus.schema :as schema :refer [validate-form]] - [plexus.transforms :as tf] [clj-manifold3d.core :as m] [malli.core :as ma] - [plexus.impl :as impl]) + [plexus.impl :as impl] + [clojure.repl :refer [demunge]] + [clojure.string :as s]) (:import [plexus.impl Form])) @@ -16,10 +16,10 @@ (cond (vector? fn-object) (into [(first fn-object)] (map pretty-demunge (subvec fn-object 1))) :else - (let [dem-fn (clojure.repl/demunge (str fn-object)) + (let [dem-fn (demunge (str fn-object)) pretty (second (re-find #"(.*?\/.*?)(--\d+)?[@].*" dem-fn))] (symbol - (if pretty (peek (clojure.string/split pretty #"/")) dem-fn))))) + (if pretty (peek (s/split pretty #"/")) dem-fn))))) (defn- get-map-key-schemas [schema] diff --git a/src/test/plexus/core_test.clj b/src/test/plexus/core_test.clj deleted file mode 100644 index 35b5c44..0000000 --- a/src/test/plexus/core_test.clj +++ /dev/null @@ -1,79 +0,0 @@ -(ns plexus.core_test - (:require - [clj-manifold3d.core :as m] - [clojure.test :as t] - [plexus.core :as p])) - -(defn get-volume [extrusion] - (-> extrusion - (p/get-model (:main-model extrusion)) - (m/get-properties) - (:volume))) - -(def default-eps 0.002) - -(def pi Math/PI) -(def pi|2 (/ pi 2)) -(def pi|2 (/ pi 2)) -(def pi|3 (/ pi 3)) -(def pi|4 (/ pi 4)) -(def pow #(Math/pow %1 %2)) - -(defn circle-area [r n] - (let [s (* 2 r (Math/sin (/ (* 2 pi) (* 2 n))))] - (/ (* n (pow s 2)) - (* 4 (Math/tan (/ pi n)))))) - -(defn about= - ([x y] (about= x y default-eps)) - ([x y eps] (< (Math/abs (- x y)) eps))) - -(t/deftest test-extrudes - (t/is (about= (get-volume - (p/extrude - (p/frame :name :body :cross-section (m/square 10 10 true)) - (p/forward :length 10))) - 1000.0)) - (let [r 10 - cr 100 - cs 200] - (t/is (about= (get-volume - (p/extrude - (p/frame :name :body :cross-section (m/circle r cs)) - (p/left :angle (* 2 pi) :curve-radius cr :cs cs))) - (* 2 (pow pi 2) (pow r 2) cr) - 200)) - (t/is (about= - 3180.828 - (get-volume - (p/extrude - (p/result :name :tmp - :expr (p/difference :body :mask)) - (p/frame :name :body :cross-section (m/circle 4) - :cs 30 - :curve-radius 30) - (p/frame :name :mask :cross-section (m/circle 3)) - (for [i (range 4)] - (p/branch - :from :body - (case i - 0 (p/left :angle pi|2) - 1 (p/right :angle pi|2) - 2 (p/up :angle pi|2) - 3 (p/down :angle pi|2)))))))))) - - -(t/deftest test-hull) - -(t/deftest test-loft) - -(t/deftest test-translate) - -(t/deftest test-rotate) - -(t/deftest test-offset) - -(t/deftest test-insert) - -(t/deftest test-) -(test-extrudes) From 9056c1d9c6178150344ea1c848cb9667d448ca8e Mon Sep 17 00:00:00 2001 From: John Collins Date: Thu, 4 Apr 2024 01:00:33 -0700 Subject: [PATCH 2/6] Install tools --- .github/workflows/test.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 05e1610..6c20a5e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -20,6 +20,16 @@ jobs: java-version: '17' distribution: 'temurin' + - name: Install clojure tools + uses: DeLaGuardo/setup-clojure@12.5 + with: + cli: 1.11.2.1446 # Clojure CLI based on tools.deps + clj-kondo: 2022.05.31 + cljfmt: 0.10.2 + cljstyle: 0.15.0 + cmd-exe-workaround: 'latest' + zprint: 1.2.3 + - name: Cache Clojure Dependencies uses: actions/cache@v2 with: From c84fe540191a79abe36a12e1c548663d19aba8eb Mon Sep 17 00:00:00 2001 From: John Collins Date: Thu, 4 Apr 2024 01:04:19 -0700 Subject: [PATCH 3/6] Add tests.edn --- tests.edn | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests.edn diff --git a/tests.edn b/tests.edn new file mode 100644 index 0000000..40b0a5b --- /dev/null +++ b/tests.edn @@ -0,0 +1 @@ +#kaocha/v1 {:test-paths "test/main"} From 2e344664602d217c2e7dd204711be7e7a9501d22 Mon Sep 17 00:00:00 2001 From: John Collins Date: Thu, 4 Apr 2024 01:06:49 -0700 Subject: [PATCH 4/6] bad cache? --- .github/workflows/test.yaml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6c20a5e..8dffedd 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,13 +30,15 @@ jobs: cmd-exe-workaround: 'latest' zprint: 1.2.3 - - name: Cache Clojure Dependencies - uses: actions/cache@v2 + - name: Cache clojure dependencies + uses: actions/cache@v3 with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/deps.edn') }} - restore-keys: | - ${{ runner.os }}-m2 + path: | + ~/.m2/repository + ~/.gitlibs + ~/.deps.clj + key: cljdeps-${{ hashFiles('deps.edn') }} + restore-keys: cljdeps- - name: Run tests run: clojure -M:dev:test From 0c721d5075349814aec02348fe0ccbea34c8abcb Mon Sep 17 00:00:00 2001 From: John Collins Date: Thu, 4 Apr 2024 01:08:20 -0700 Subject: [PATCH 5/6] Add test file --- test/main/plexus/core_test.clj | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/main/plexus/core_test.clj diff --git a/test/main/plexus/core_test.clj b/test/main/plexus/core_test.clj new file mode 100644 index 0000000..986d5d9 --- /dev/null +++ b/test/main/plexus/core_test.clj @@ -0,0 +1,62 @@ +(ns plexus.core-test + (:require + [clj-manifold3d.core :as m] + [clojure.test :as t] + [plexus.core :as p])) + +(defn get-volume [extrusion] + (-> extrusion + (p/get-model (:main-model extrusion)) + (m/get-properties) + (:volume))) + +(def default-eps 0.002) + +(def pi Math/PI) +(def pi|2 (/ pi 2)) +(def pi|3 (/ pi 3)) +(def pi|4 (/ pi 4)) +(def pow #(Math/pow %1 %2)) + +(defn circle-area [r n] + (let [s (* 2 r (Math/sin (/ (* 2 pi) (* 2 n))))] + (/ (* n (pow s 2)) + (* 4 (Math/tan (/ pi n)))))) + +(defn about= + ([x y] (about= x y default-eps)) + ([x y eps] (< (Math/abs (- x y)) eps))) + +(t/deftest test-extrudes + (t/is (about= (get-volume + (p/extrude + (p/frame :name :body :cross-section (m/square 10 10 true)) + (p/forward :length 10))) + 1000.0)) + (let [r 10 + cr 100 + cs 200] + (t/is (about= (get-volume + (p/extrude + (p/frame :name :body :cross-section (m/circle r cs)) + (p/left :angle (* 2 pi) :curve-radius cr :cs cs))) + (* 2 (pow pi 2) (pow r 2) cr) + 200)) + (t/is (about= + 3180.828 + (get-volume + (p/extrude + (p/result :name :tmp + :expr (p/difference :body :mask)) + (p/frame :name :body :cross-section (m/circle 4) + :cs 30 + :curve-radius 30) + (p/frame :name :mask :cross-section (m/circle 3)) + (for [i (range 4)] + (p/branch + :from :body + (case i + 0 (p/left :angle pi|2) + 1 (p/right :angle pi|2) + 2 (p/up :angle pi|2) + 3 (p/down :angle pi|2)))))))))) From 2e87ba00003cbf5775e08fda37b696f1a0b7e790 Mon Sep 17 00:00:00 2001 From: John Collins Date: Thu, 4 Apr 2024 01:10:59 -0700 Subject: [PATCH 6/6] install libassimp --- .github/workflows/test.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8dffedd..eb7f438 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -40,5 +40,8 @@ jobs: key: cljdeps-${{ hashFiles('deps.edn') }} restore-keys: cljdeps- + - name: Install libassimp + run: sudo apt-get update && sudo apt-get install -y libassimp-dev + - name: Run tests run: clojure -M:dev:test