Skip to content

Commit 1841090

Browse files
Merge pull request #24 from OSCPS-Project/fix-thermo-test-fail
Fix thermo test fail
2 parents cb6d50d + c9b8e25 commit 1841090

4 files changed

Lines changed: 71 additions & 6 deletions

File tree

oscps-gui/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "oscps-gui"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
iced = "0.13.1"

oscps-gui/src/main.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#[derive(Default)]
2+
struct Counter {
3+
value: i8,
4+
}
5+
#[derive(Debug, Clone, Copy)]
6+
pub enum Message {
7+
Increment,
8+
Decrement,
9+
}
10+
use iced::widget::{button, row, text, Row};
11+
impl Counter {
12+
pub fn view(&self) -> Row<Message> {
13+
row![
14+
button("+").on_press(Message::Increment),
15+
text(self.value).size(50),
16+
button("-").on_press(Message::Decrement),
17+
]
18+
}
19+
pub fn update(&mut self, message: Message) {
20+
match message {
21+
Message::Increment => {
22+
self.value += 1;
23+
}
24+
Message::Decrement => {
25+
self.value -= 1;
26+
}
27+
}
28+
}
29+
}
30+
fn main() -> iced::Result {
31+
iced::run("A cool counter", Counter::update, Counter::view)
32+
}

oscps-lib/src/component.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ extern crate uom;
66

77
extern crate pubchem;
88
use anyhow::Result;
9+
use std::{thread,time::Duration};
10+
911

1012
#[allow(dead_code)]
1113
/// This will hold the list of chemicals used within the simulation
@@ -43,9 +45,23 @@ impl Chemical {
4345
ChemicalIdentifier::PubchemID(id) => pubchem::Compound::new(id),
4446
ChemicalIdentifier::CompoundName(name) => pubchem::Compound::with_name(name.as_str()),
4547
};
46-
47-
let cid_vec = pubchem_chemical_object.cids().unwrap();
48-
let cid: i32 = cid_vec[0];
48+
let mut request_counter = 0;
49+
let mut cid_vec = None;
50+
while request_counter <= 10 {
51+
match pubchem_chemical_object.cids(){
52+
Ok(cid_list) => {
53+
cid_vec = Some(cid_list);
54+
break;
55+
},
56+
_ => {
57+
request_counter = request_counter + 1;
58+
thread::sleep(Duration::from_secs(10));
59+
}
60+
};
61+
}
62+
63+
// let cid_vec = pubchem_chemical_object.cids().unwrap();
64+
let cid: i32 = cid_vec.unwrap()[0];
4965
let prop = ChemicalProperties::new(cid).unwrap();
5066
return Ok(Chemical {
5167
pubchem_obj: pubchem_chemical_object,
@@ -93,14 +109,16 @@ impl ChemicalProperties {
93109
#[cfg(test)]
94110
mod chemical_species_tests {
95111
use crate::component::{Chemical, ChemicalIdentifier};
112+
use std::{thread,time::Duration};
96113

97114
#[test]
98115
fn test_create_chemical_from_pubchem_id() {
99116
// Using a known PubChem ID, e.g., 7732 (water)
100117
let identifier = ChemicalIdentifier::PubchemID(7732);
101118

102119
let chemical = Chemical::new(identifier);
103-
120+
thread::sleep(Duration::from_secs(10));
121+
104122
assert!(
105123
chemical.is_ok(),
106124
"Failed to create chemical from PubChem ID"
@@ -119,6 +137,8 @@ mod chemical_species_tests {
119137
let identifier = ChemicalIdentifier::CompoundName(String::from("Water"));
120138

121139
let chemical = Chemical::new(identifier);
140+
thread::sleep(Duration::from_secs(10));
141+
122142

123143
assert!(chemical.is_ok(), "Failed to create chemical from name");
124144
let chemical = chemical.unwrap();

oscps-lib/src/thermodynamics.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl ThermoState {
9393
ThermoState {
9494
pressure: Pressure::new::<pascal>(pressure),
9595
temperature: ThermodynamicTemperature::new::<kelvin>(temperature),
96-
mass_list: mass_list,
96+
mass_list,
9797
}
9898
}
9999

@@ -132,6 +132,7 @@ mod thermo_tests {
132132
use uom::si::mass::kilogram;
133133
use uom::si::pressure::pascal;
134134
use uom::si::thermodynamic_temperature::kelvin;
135+
use std::{thread,time::Duration};
135136

136137
#[test]
137138
///Test case generates an instance of the 'ThermoState' struct
@@ -146,6 +147,7 @@ mod thermo_tests {
146147
acentric_factor: 0.344, // example
147148
},
148149
};
150+
thread::sleep(Duration::from_secs(10));
149151
let water_mass = Mass::new::<kilogram>(2.0);
150152
let water_species_pair = SpeciesListPair {
151153
chemical_species: water,
@@ -164,6 +166,8 @@ mod thermo_tests {
164166
assert_eq!(thermo_state.temperature.get::<kelvin>(), 298.15);
165167
assert_eq!(thermo_state.mass_list.len(), 1); // Should contain one mole fraction entry
166168

169+
170+
167171
// Check that the mole fraction's chemical is correctly set
168172
assert_eq!(
169173
thermo_state.mass_list[0]
@@ -187,6 +191,7 @@ mod thermo_tests {
187191
acentric_factor: 0.344, // example
188192
},
189193
};
194+
thread::sleep(Duration::from_secs(10));
190195

191196
let anisdine = Chemical {
192197
pubchem_obj: pubchem::Compound::new(7732),
@@ -197,7 +202,8 @@ mod thermo_tests {
197202
acentric_factor: 0.24, // (approximated)
198203
},
199204
};
200-
205+
thread::sleep(Duration::from_secs(10));
206+
201207
let water_mass = Mass::new::<kilogram>(2.0);
202208
let water_species_pair = SpeciesListPair {
203209
chemical_species: water,

0 commit comments

Comments
 (0)