Skip to content

Commit

Permalink
Convert the test simulations to integration tests - making them bette…
Browse files Browse the repository at this point in the history
…r examples that only use the public API
  • Loading branch information
ndebuhr committed Mar 24, 2021
1 parent a434aed commit 870e7f4
Show file tree
Hide file tree
Showing 3 changed files with 714 additions and 573 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ npm i sim-rs

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

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

### Creating Simulations
Simulation definitions are defined in a declarative YAML or JSON format, and then ingested through `Simulation`'s `post_yaml` or `post_json` constructors.

Rust simulations are created by passing `Model`s and `Connector`s to `Simulation`'s `post` constructor.

WebAssembly simulations are defined in a declarative YAML or JSON format, and then ingested through `WebSimulation`'s `post_yaml` or `post_json` constructors.

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:

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

## Contributing

Issues, feature requests and pull requests are always welcome!
Issues, feature requests, and pull requests are always welcome!

## License

Expand Down
23 changes: 20 additions & 3 deletions src/simulator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ use crate::models::{AsModel, Model, ModelMessage};
use crate::utils;
use crate::utils::error::SimulationError;

#[cfg(test)]
mod test_simulations;

/// Connectors are configured to connect models through their ports. During
/// simulation, models exchange messages (as per the Discrete Event System
/// Specification) via these connectors.
Expand Down Expand Up @@ -78,6 +75,26 @@ pub struct Message {
}

impl Message {
/// This constructor method builds a `Message`, which is passed between
/// simulation models
pub fn new(
source_id: String,
source_port: String,
target_id: String,
target_port: String,
time: f64,
content: String,
) -> Self {
Self {
source_id,
source_port,
target_id,
target_port,
time,
content,
}
}

/// This accessor method returns the model ID of a message source.
pub fn source_id(&self) -> &str {
&self.source_id
Expand Down
Loading

0 comments on commit 870e7f4

Please sign in to comment.