Skip to content

Commit

Permalink
Unit test for execution plan which draws a cube
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchalmers committed Dec 16, 2023
1 parent 80a27d2 commit c73993a
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 24 deletions.
208 changes: 208 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions execution-plan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ bytes = "1.5"
kittycad = { version = "0.2.44", features = ["requests"] }
kittycad-modeling-cmds = { path = "../modeling-cmds" }
kittycad-modeling-session = { path = "../modeling-session" }
parse-display-derive = "0.8.2"
serde = { version = "1", features = ["derive"] }
thiserror = "1"
tokio = { version = "1.35.0", features = ["rt", "macros"] }
uuid = "1.6.1"

[lints]
workspace = true

[dev-dependencies]
image = { version = "0.24.7", default-features = false, features = ["png"] }
tabled = "0.14.0"
twenty-twenty = "0.6.1"
10 changes: 7 additions & 3 deletions execution-plan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ impl Memory {

/// Store a value value (i.e. a value which takes up multiple addresses in memory).
/// Store its parts in consecutive memory addresses starting at `start`.
pub fn set_composite<T: Value>(&mut self, start: Address, composite_value: T) {
/// Returns how many memory addresses the data took up.
pub fn set_composite<T: Value>(&mut self, start: Address, composite_value: T) -> usize {
let parts = composite_value.into_parts().into_iter();
let mut total_addrs = 0;
for (value, addr) in parts.zip(start.0..) {
self.0[addr] = Some(value);
total_addrs += 1;
}
total_addrs
}

/// Get a value value (i.e. a value which takes up multiple addresses in memory).
Expand Down Expand Up @@ -118,7 +122,7 @@ pub struct ApiRequest {
}

/// A KittyCAD modeling command.
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, parse_display_derive::Display)]
pub enum Endpoint {
#[allow(missing_docs)]
StartPath,
Expand Down Expand Up @@ -226,7 +230,7 @@ impl Operand {

/// Execute the plan.
pub async fn execute(mem: &mut Memory, plan: Vec<Instruction>, mut session: ModelingSession) -> Result<()> {
for step in plan {
for (_step_number, step) in plan.into_iter().enumerate() {
match step {
Instruction::ApiRequest(req) => {
req.execute(&mut session, mem).await?;
Expand Down
Loading

0 comments on commit c73993a

Please sign in to comment.