shuttle-hq / synth

The Declarative Data Generator
https://www.getsynth.com/
Apache License 2.0
1.39k stars 109 forks source link

Utilize weights in OneOf #208

Closed hbina closed 3 years ago

hbina commented 3 years ago
  1. Utilizes the weights when choosing the next variant.
  2. Use swap_remove which have O(1) since we don't care about the order.

Small demo

synth/examples/random_variants on  hbina-ISSUE-149-utilize-weights-in-oneof on ☁️  (ap-southeast-1) 
❯ cargo run --bin synth -- generate random --size 1 | jq | rg '1' | wc -l
warning: /home/hbina/git/synth/synth/Cargo.toml: unused manifest key: target.i686-pc-windows-msvc.rustflags
warning: /home/hbina/git/synth/synth/Cargo.toml: unused manifest key: target.x86_64-pc-windows-msvc.rustflags
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `/home/hbina/git/synth/target/debug/synth generate random --size 1`
9930

synth/examples/random_variants on  hbina-ISSUE-149-utilize-weights-in-oneof on ☁️  (ap-southeast-1) 
❯ cargo run --bin synth -- generate random --size 1 | jq | rg '2' | wc -l
warning: /home/hbina/git/synth/synth/Cargo.toml: unused manifest key: target.i686-pc-windows-msvc.rustflags
warning: /home/hbina/git/synth/synth/Cargo.toml: unused manifest key: target.x86_64-pc-windows-msvc.rustflags
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `/home/hbina/git/synth/target/debug/synth generate random --size 1`
70

Closes https://github.com/getsynth/synth/issues/149

hbina commented 3 years ago

Can someone figure out a way to generate the seed here?

synth/examples/random_variants on  hbina-ISSUE-149-utilize-weights-in-oneof [?] on ☁️  (ap-southeast-1) 
❯ cargo run --bin synth -- generate random --size 1 --seed $(od -vAn -N2 -tu2 < /dev/urandom)  | jq | rg '1' | wc -l
warning: /home/hbina/git/synth/synth/Cargo.toml: unused manifest key: target.i686-pc-windows-msvc.rustflags
warning: /home/hbina/git/synth/synth/Cargo.toml: unused manifest key: target.x86_64-pc-windows-msvc.rustflags
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `/home/hbina/git/synth/target/debug/synth generate random --size 1 --seed ' 57622'`
error: Invalid value for '--seed <seed>': invalid digit found in string
0
brokad commented 3 years ago

Can someone figure out a way to generate the seed here?

I can think of two ways:

hbina commented 3 years ago

@brokad is there an automated way to generate the SQL script for the test harnesses?

brokad commented 3 years ago

@brokad is there an automated way to generate the SQL script for the test harnesses?

Unfortunately there isn't. Pinging @fretz12, who wrote all those tests: do you have local scripts you can share for this maybe?

fretz12 commented 3 years ago

@brokad @hbina -

I assume you're referring to 0_hospital_schema.sql and 1_hospital_data.sql. FYI those scripts were already there when i came in. I did copy them over for mysql test harness and had to modify them slightly to suit mysql.

Sorry couldn't be of more help.

christos-h commented 3 years ago

Hmm - I think there is a new clippy lint out. I'll take a look.