Replace most panics in the core library with results
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2023-04-19 18:44:11 +02:00
parent 00d596d656
commit c0e4702e45
33 changed files with 222 additions and 102 deletions

View File

@@ -121,7 +121,9 @@ pub fn load_types(path: &String) -> Box<dyn TypeLibrary> {
for (i, v) in record.iter().skip(1).enumerate() {
let effectiveness = v.parse::<f32>().unwrap();
type_library.set_effectiveness(offensive_type_id, ((i + 1) as u8).into(), effectiveness);
type_library
.set_effectiveness(offensive_type_id, ((i + 1) as u8).into(), effectiveness)
.unwrap();
}
}
type_library
@@ -463,7 +465,7 @@ fn parse_moves(value: &Value, move_library: &Box<dyn MoveLibrary>) -> Box<dyn Le
let name = level_move.get("name").unwrap().as_str().unwrap().into();
let level = level_move.get("level").unwrap().as_u64().unwrap() as LevelInt;
assert!(move_library.get(&name).is_some());
moves.add_level_move(level, &name);
moves.add_level_move(level, &name).unwrap();
}
Box::new(moves)
@@ -500,10 +502,12 @@ fn test_type_library_loaded() {
let types = load_types(&path.to_str().unwrap().to_string());
assert_eq!(
types.get_effectiveness(
types.get_type_id(&"fire".into()).unwrap(),
&[types.get_type_id(&"grass".into()).unwrap()],
),
types
.get_effectiveness(
types.get_type_id(&"fire".into()).unwrap(),
&[types.get_type_id(&"grass".into()).unwrap()],
)
.unwrap(),
2.0
);
}