Skip to content

Commit

Permalink
Merge pull request #7 from MattFerraro/fix_rust_tests
Browse files Browse the repository at this point in the history
Fix rust tests
  • Loading branch information
MattFerraro authored Apr 8, 2024
2 parents 4d46af3 + 5c70392 commit faedbe0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ concurrency:

jobs:
build:
name: Build, Test & Deploy
name: Build and Test
timeout-minutes: 15
runs-on: ubuntu-latest
# env:
Expand Down Expand Up @@ -57,10 +57,12 @@ jobs:
run: pnpm exec playwright install
- name: Build
env:
BASE_PATH: '/${{ github.event.repository.name }}'
BASE_PATH: "/${{ github.event.repository.name }}"
run: pnpm turbo run build
- name: Test
- name: Test Web
run: pnpm turbo run test
- name: Test Rust
run: pnpm run test:rust
- uses: actions/upload-artifact@v4
with:
name: cadmium
Expand All @@ -72,7 +74,7 @@ jobs:
with:
path: applications/web/dist

# https://kit.svelte.dev/docs/adapter-static#github-pages
# https://kit.svelte.dev/docs/adapter-static#github-pages
deploy:
needs: build
runs-on: ubuntu-latest
Expand All @@ -88,4 +90,4 @@ jobs:
steps:
- name: Deploy
id: deployment
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@v4
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dev": "turbo run dev",
"serve": "turbo run serve",
"test": "turbo run test",
"test:rust": "cd packages/cadmium && cargo test",
"clean": "turbo run clean",
"lint": "turbo run lint",
"format": "turbo run format",
Expand All @@ -20,4 +21,4 @@
"node": ">=20.12.0",
"pnpm": ">=8.15.5"
}
}
}
6 changes: 6 additions & 0 deletions packages/cadmium/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "cadmium-root",
"scripts": {
"test": "cargo test"
}
}
19 changes: 19 additions & 0 deletions packages/cadmium/src/sketch/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::f64::consts::PI;

use svg::node::element::path::Data;
// use svg::node::element::Circle;
use std::fs;
use svg::node::element::Path;
use svg::Document;

Expand Down Expand Up @@ -255,6 +256,7 @@ mod tests {
#[test]
fn empty_to_svg() {
let mut sketch = Sketch::new();
fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/empty.svg");
}

Expand All @@ -273,6 +275,7 @@ mod tests {
sketch.add_segment(center, left);
sketch.add_segment(center, bottom);

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/no_rings.svg");
}

Expand All @@ -283,6 +286,7 @@ mod tests {
let id0 = sketch.add_point(1.0, 0.0);
sketch.add_circle(id0, 1.0);

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/circle.svg");
}

Expand All @@ -300,6 +304,7 @@ mod tests {
sketch.add_segment(id2, id3);
sketch.add_segment(id3, id0);

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/square.svg");
}

Expand Down Expand Up @@ -329,6 +334,7 @@ mod tests {
sketch.add_segment(g, h);
sketch.add_arc(l, h, a, false);

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/rounded_square.svg");
}

Expand Down Expand Up @@ -356,6 +362,7 @@ mod tests {
sketch.add_segment(g, h);
sketch.add_segment(h, e);

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/square_with_hole.svg");
}

Expand All @@ -376,6 +383,7 @@ mod tests {

sketch.add_circle(center, 0.4);

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/square_with_circular_hole.svg");
}

Expand All @@ -388,6 +396,7 @@ mod tests {
sketch.add_circle(center, 0.5);
sketch.add_circle(center, 0.25);

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/circle_with_circular_hole.svg");
}

Expand All @@ -408,6 +417,7 @@ mod tests {

sketch.add_circle(center, 1.0);

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/circle_with_square_hole.svg");
}

Expand All @@ -433,6 +443,7 @@ mod tests {
sketch.add_segment(g, h);
sketch.add_segment(h, e);

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/two_intersecting_squares_unsplit.svg");

let sketch = sketch.split_intersections(false);
Expand All @@ -451,6 +462,7 @@ mod tests {
sketch.add_circle(center_b, 1.0);

// Save the naive svg: just two circular paths
fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/two_intersecting_circles_unsplit.svg");

// Split the intersections, creating a new and different sketch
Expand All @@ -474,6 +486,7 @@ mod tests {
println!("Error: {}", sketch.constraint_error(constraint_id));
assert!(sketch.constraint_is_satisfied(constraint_id));

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/constraint_circle_diameter.svg");
}

Expand All @@ -492,6 +505,7 @@ mod tests {

let constraint_id = sketch.add_segments_equal_constraint(segment_ab, segment_cd);

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/equality_constraint_unsolved.svg");
assert!(sketch.solve(1000));
sketch.save_svg("test_svgs/equality_constraint_solved.svg");
Expand Down Expand Up @@ -519,6 +533,7 @@ mod tests {

assert!(sketch.all_constraints_are_satisfied());

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/constraint_triangle.svg");
}

Expand All @@ -533,6 +548,7 @@ mod tests {
sketch.add_arc(center, right, top, false);
sketch.add_arc(center, top, right, false);

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/two_arcs_in_a_circle_90.svg");
}

Expand All @@ -547,6 +563,7 @@ mod tests {
sketch.add_arc(center, bottom, top, false);
sketch.add_arc(center, top, bottom, false);

fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/two_arcs_in_a_circle_180.svg");
}

Expand Down Expand Up @@ -581,6 +598,7 @@ mod tests {
// }

sketch.solve(1000);
fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/manual_square_solved.svg");
}

Expand Down Expand Up @@ -616,6 +634,7 @@ mod tests {

let solved = sketch.solve(1000);
println!("did solve? {}", solved);
fs::create_dir_all("test_svgs");
sketch.save_svg("test_svgs/manual_rectangle_solved.svg");
}
}
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit faedbe0

Please sign in to comment.