Skip to content

Commit 870e7f4

Browse files
committed
Convert the test simulations to integration tests - making them better examples that only use the public API
1 parent a434aed commit 870e7f4

File tree

3 files changed

+714
-573
lines changed

3 files changed

+714
-573
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ npm i sim-rs
5858

5959
Please refer to the documentation at [https://docs.rs/sim](https://docs.rs/sim)
6060

61-
Also, the [test simulations](src/simulator/test_simulations.rs) are a good reference for creating, running, and analyzing simulations with Sim.
61+
Also, the [test simulations](tests/simulations.rs) are a good reference for creating, running, and analyzing simulations with Sim.
6262

6363
### Creating Simulations
64-
Simulation definitions are defined in a declarative YAML or JSON format, and then ingested through `Simulation`'s `post_yaml` or `post_json` constructors.
64+
65+
Rust simulations are created by passing `Model`s and `Connector`s to `Simulation`'s `post` constructor.
66+
67+
WebAssembly simulations are defined in a declarative YAML or JSON format, and then ingested through `WebSimulation`'s `post_yaml` or `post_json` constructors.
6568

6669
Both models and connectors are required to define the simulation. For descriptions of the pre-built models, see [MODELS.md](MODELS.md) A simple three-model simulation could be defined as:
6770

@@ -116,7 +119,7 @@ Analyzing simulations will typically involve some combination of listening to mo
116119

117120
## Contributing
118121

119-
Issues, feature requests and pull requests are always welcome!
122+
Issues, feature requests, and pull requests are always welcome!
120123

121124
## License
122125

src/simulator/mod.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ use crate::models::{AsModel, Model, ModelMessage};
2525
use crate::utils;
2626
use crate::utils::error::SimulationError;
2727

28-
#[cfg(test)]
29-
mod test_simulations;
30-
3128
/// Connectors are configured to connect models through their ports. During
3229
/// simulation, models exchange messages (as per the Discrete Event System
3330
/// Specification) via these connectors.
@@ -78,6 +75,26 @@ pub struct Message {
7875
}
7976

8077
impl Message {
78+
/// This constructor method builds a `Message`, which is passed between
79+
/// simulation models
80+
pub fn new(
81+
source_id: String,
82+
source_port: String,
83+
target_id: String,
84+
target_port: String,
85+
time: f64,
86+
content: String,
87+
) -> Self {
88+
Self {
89+
source_id,
90+
source_port,
91+
target_id,
92+
target_port,
93+
time,
94+
content,
95+
}
96+
}
97+
8198
/// This accessor method returns the model ID of a message source.
8299
pub fn source_id(&self) -> &str {
83100
&self.source_id

0 commit comments

Comments
 (0)