Skip to content

Commit

Permalink
Merge branch 'dev-testing' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfierrog committed Apr 10, 2024
2 parents c5b5e87 + ea200c2 commit 7905b51
Show file tree
Hide file tree
Showing 37 changed files with 254 additions and 79 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# Profiling output
flamegraph.svg

# Development data
/data
27 changes: 27 additions & 0 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ lto = "fat"
clap = { version = "^4", features = ["derive"] }
serde_json = "^1"
exitcode = "^1"
petgraph = "^0"
nalgebra = "^0"
colored = "^2"
anyhow = "^1"
bitvec = "^1"
regex = "^1"

[dev-dependencies]
strum_macros = "0.26"
petgraph = "^0"
strum = "0.26"
1 change: 0 additions & 1 deletion src/database/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//! under which all database implementations' errors can be grouped into).
//!
//! #### Authorship
//!
//! - Max Fierro, 2/24/2024 (maxfierro@berkeley.edu)

use std::{error::Error, fmt};
Expand Down
1 change: 0 additions & 1 deletion src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! solution set data, hopefully in an efficient and scalable way.
//!
//! #### Authorship
//!
//! - Max Fierro, 4/14/2023 (maxfierro@berkeley.edu)

use anyhow::Result;
Expand Down
3 changes: 1 addition & 2 deletions src/database/test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! # Database Test Module
//! # Database Test Utilities Module
//!
//! This module provides integration tests for the database module.
//!
//! #### Authorship
//!
//! - Benjamin Riley Zimmerman, 3/8/2024 (bz931@berkely.edu)

// #[test]
Expand Down
1 change: 0 additions & 1 deletion src/database/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//! leaving this for cases where their functionality intersects.
//!
//! #### Authorship
//!
//! - Max Fierro, 2/24/2024 (maxfierro@berkeley.edu)

use anyhow::Result;
Expand Down
1 change: 0 additions & 1 deletion src/database/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//! of memory may be materialized on arbitrary operations.
//!
//! #### Authorship
//!
//! - Max Fierro, 4/14/2023 (maxfierro@berkeley.edu)

use anyhow::Result;
Expand Down
1 change: 0 additions & 1 deletion src/database/volatile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! in-memory hashmap.
//!
//! #### Authorship
//!
//! - Max Fierro, 2/24/2024 (maxfierro@berkeley.edu)

use anyhow::Result;
Expand Down
1 change: 0 additions & 1 deletion src/game/crossteaser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//! [1]: https://www.jaapsch.net/puzzles/crosstsr.htm
//!
//! #### Authorship
//!
//! - Max Fierro, 11/5/2023 (maxfierro@berkeley.edu)
//! - Cindy Xu, 11/28/2023

Expand Down
1 change: 0 additions & 1 deletion src/game/crossteaser/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
//! which partially ensure compatibility with a game variant.
//!
//! #### Authorship
//!
//! - Max Fierro, 3/7/2023 (maxfierro@berkeley.edu)
1 change: 0 additions & 1 deletion src/game/crossteaser/variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! game into parameters that can help build a game session.
//!
//! #### Authorship
//!
//! - Max Fierro, 11/5/2023 (maxfierro@berkeley.edu)
//! - Atharva Gupta, 11/28/2023
//! - Cindy Xu, 11/28/2023
Expand Down
8 changes: 0 additions & 8 deletions src/game/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! input or an incomplete game implementation.
//!
//! #### Authorship
//!
//! - Max Fierro, 2/24/2024 (maxfierro@berkeley.edu)

use std::{error::Error, fmt};
Expand Down Expand Up @@ -48,12 +47,6 @@ pub enum GameError {
game_name: &'static str,
hint: String,
},

/// An error to indicate that a game-building rule within the abstract
/// extensive mock game implementation was violated during construction.
/// Since this is intended as an internal feature, it is a very general
/// error variant.
MockViolation { hint: String },
}

impl Error for GameError {}
Expand Down Expand Up @@ -93,7 +86,6 @@ impl fmt::Display for GameError {
hint, game_name
)
},
Self::MockViolation { hint } => write!(f, "{}", hint),
}
}
}
49 changes: 27 additions & 22 deletions src/game/mock/builder.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
//! Mock Extensive Game Builder Pattern Module
//! Mock Extensive Test Game Builder Pattern Module
//!
//! This module provides an implementation of a declarative builder pattern for
//! an extensive-form game `Session`, which allows the construction of a graph
//! of nodes representing game states.
//!
//! #### Authorship
//!
//! - Max Fierro, 3/31/2024
//! - Max Fierro, 3/31/2024 (maxfierro@gmail.com)

use anyhow::anyhow;
use anyhow::Result;
use petgraph::Direction;
use petgraph::{graph::NodeIndex, Graph};

use std::collections::{HashMap, HashSet};

use crate::game::error::GameError::MockViolation;
use crate::game::mock::Node;
use crate::game::mock::Session;
use crate::model::PlayerCount;
Expand Down Expand Up @@ -81,8 +80,8 @@ impl<'a> SessionBuilder<'a> {
/// count that is incompatible with existing nodes.
pub fn edge(mut self, from: &'a Node, to: &'a Node) -> Result<Self> {
if let Node::Terminal(_) = from {
Err(MockViolation {
hint: format!(
Err(anyhow! {
format!(
"There was an attempt to add a terminal node on the \
outgoing side of an edge during the construction of the \
game '{}'.",
Expand Down Expand Up @@ -120,8 +119,8 @@ impl<'a> SessionBuilder<'a> {
self.start = Some(index);
Ok(self)
} else {
Err(MockViolation {
hint: format!(
Err(anyhow! {
format!(
"There was an attempt to set the start state of mock game \
'{}', but the indicated start node has not been added to \
the game yet.",
Expand Down Expand Up @@ -160,8 +159,8 @@ impl<'a> SessionBuilder<'a> {
Node::Terminal(vector) => {
let result = vector.len();
if result == 0 {
Err(MockViolation {
hint: format!(
Err(anyhow! {
format!(
"While constructing the game '{}', there was an \
attempt to add a terminal node with containing no \
utility entries. Games with no players are not \
Expand All @@ -177,8 +176,8 @@ impl<'a> SessionBuilder<'a> {

if finalized {
if new.terminal() && old_count != new_count {
Err(MockViolation {
hint: format!(
Err(anyhow! {
format!(
"While constructing the game '{}', a terminal node was \
added containing {} utility entries, but then a new \
one was added with {} entries. Utility entries must be \
Expand All @@ -187,8 +186,8 @@ impl<'a> SessionBuilder<'a> {
),
})?
} else if new.medial() && new_count > old_count {
Err(MockViolation {
hint: format!(
Err(anyhow! {
format!(
"While constructing the game '{}', a terminal node was \
added containing {} utility entries, but then a new \
medial node was added with a 0-indexed turn of {}, \
Expand All @@ -201,8 +200,8 @@ impl<'a> SessionBuilder<'a> {
}
} else {
if new.terminal() && new_count < old_count {
Err(MockViolation {
hint: format!(
Err(anyhow! {
format!(
"While constructing the game '{}', a medial node was \
added with a 0-indexed turn of {}, but then a new \
terminal node was added with {} entries. All turn \
Expand Down Expand Up @@ -230,8 +229,8 @@ impl<'a> SessionBuilder<'a> {
if let Some(index) = self.start {
Ok(index)
} else {
Err(MockViolation {
hint: format!(
Err(anyhow! {
format!(
"No starting node was specified for the game '{}'.",
self.name,
),
Expand Down Expand Up @@ -263,8 +262,8 @@ impl<'a> SessionBuilder<'a> {
}
}

Err(MockViolation {
hint: format!(
Err(anyhow! {
format!(
"No terminal node is reachable from the node marked as the \
start in the game '{}'.",
self.name
Expand All @@ -283,8 +282,8 @@ impl<'a> SessionBuilder<'a> {
.count()
.eq(&0)
}) {
Err(MockViolation {
hint: format!(
Err(anyhow! {
format!(
"There exists a medial state with no outgoing edges in the \
constructed game '{}', which is a contradiction.",
self.name
Expand Down Expand Up @@ -326,6 +325,10 @@ mod tests {
use super::*;
use crate::node;

/// Used for storing generated visualizations of the mock games being used
/// for testing purposes in this module under their own subdirectory.
const MODULE_NAME: &str = "mock-builder-tests";

#[test]
fn cannot_add_incorrect_utility_entries() -> Result<()> {
let m1 = node!(0);
Expand Down Expand Up @@ -475,6 +478,7 @@ mod tests {
.start(&a)?
.build()?;

game.visualize(MODULE_NAME)?;
assert_eq!(game.players, 2);

Ok(())
Expand Down Expand Up @@ -505,6 +509,7 @@ mod tests {
.start(&a)?
.build()?;

game.visualize(MODULE_NAME)?;
assert_eq!(game.players, 4);

Ok(())
Expand Down
3 changes: 1 addition & 2 deletions src/game/mock/example.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Example Mock Game Module
//! Example Mock Test Game Module
//!
//! This module provides concrete examples of small games that adhere to useful
//! interface definitions that can be used for testing purposes. The games here
//! are built over the `mock` game graph implementation.
//!
//! #### Authorship
//!
//! - Max Fierro, 4/8/2024
Loading

0 comments on commit 7905b51

Please sign in to comment.