Skip to content

Commit

Permalink
completed fleet view tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Oct 27, 2023
1 parent e06b8fd commit 69eb412
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/game/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,10 @@ mod NoGame {
fleet: Fleet,
techs: TechLevels
) -> u64 {
let destination_id = self
.position_to_planet_id
.read(self.get_raw_from_position(destination));
assert(!destination_id.is_zero(), 'no planet at destination');
let distance = fleet::get_distance(origin, destination);
let speed = fleet::get_fleet_speed(fleet, techs);
fleet::get_flight_time(speed, distance)
Expand Down
90 changes: 84 additions & 6 deletions tests/view_tests/fleet_view.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use nogame::libraries::types::{
use nogame::token::erc20::{INGERC20Dispatcher, INGERC20DispatcherTrait};
use nogame::token::erc721::{IERC721NoGameDispatcher, IERC721NoGameDispatcherTrait};
use tests::utils::{
E18, HOUR, Dispatchers, ACCOUNT1, ACCOUNT2, init_game, set_up, build_basic_mines,
advance_game_state
E18, HOUR, Dispatchers, ACCOUNT1, ACCOUNT2, ACCOUNT3, ACCOUNT4, init_game, set_up,
build_basic_mines, advance_game_state
};

#[test]
Expand Down Expand Up @@ -183,11 +183,89 @@ fn test_get_active_missions() {
}

#[test]
fn test_get_travel_time() { // TODO
assert(0 == 0, 'todo');
fn test_get_travel_time() {
let dsp = set_up();
init_game(dsp);

start_prank(dsp.game.contract_address, ACCOUNT1());
dsp.game.generate_planet();
start_prank(dsp.game.contract_address, ACCOUNT2());
dsp.game.generate_planet();

let p1 = dsp.game.get_planet_position(1);
let p2 = dsp.game.get_planet_position(2);

let mut f1: Fleet = Default::default();
f1.carrier = 1;
let mut f2: Fleet = Default::default();
f2.scraper = 1;
let mut f3: Fleet = Default::default();
f3.sparrow = 1;
let mut f4: Fleet = Default::default();
f4.frigate = 1;
let mut f4: Fleet = Default::default();
f4.frigate = 1;
let mut f5: Fleet = Default::default();
f5.armade = 1;

let mut techs: TechLevels = Default::default();
techs.thrust = 4;
techs.spacetime = 3;

let t1 = dsp.game.get_travel_time(p1, p2, f1, Default::default());
assert(t1 == 11892, 'wrong assert #1');

let t2 = dsp.game.get_travel_time(p1, p2, f2, Default::default());
assert(t2 == 18803, 'wrong assert #2');

let t3 = dsp.game.get_travel_time(p1, p2, f3, Default::default());
assert(t3 == 7521, 'wrong assert #3');

let t4 = dsp.game.get_travel_time(p1, p2, f4, techs);
assert(t4 == 6866, 'wrong assert #4');

let t5 = dsp.game.get_travel_time(p1, p2, f5, techs);
assert(t5 == 8409, 'wrong assert #5');
}

#[test]
fn test_get_fuel_consumption() { // TODO
assert(0 == 0, 'todo');
fn test_get_fuel_consumption() {
let dsp = set_up();
init_game(dsp);

start_prank(dsp.game.contract_address, ACCOUNT1());
dsp.game.generate_planet();
start_prank(dsp.game.contract_address, ACCOUNT2());
dsp.game.generate_planet();

let p1 = dsp.game.get_planet_position(1);
let p2 = dsp.game.get_planet_position(2);

let mut f1: Fleet = Default::default();
f1.carrier = 1;
let mut f2: Fleet = Default::default();
f2.scraper = 1;
let mut f3: Fleet = Default::default();
f3.sparrow = 1;
let mut f4: Fleet = Default::default();
f4.frigate = 1;
let mut f4: Fleet = Default::default();
f4.frigate = 1;
let mut f5: Fleet = Default::default();
f5.armade = 1;

let c1 = dsp.game.get_fuel_consumption(p1, p2, f1);
assert(c1 == 1, 'wrong assert #1');

let c2 = dsp.game.get_fuel_consumption(p1, p2, f2);
assert(c2 == 49, 'wrong assert #2');

let c3 = dsp.game.get_fuel_consumption(p1, p2, f3);
assert(c3 == 3, 'wrong assert #3');

let c4 = dsp.game.get_fuel_consumption(p1, p2, f4);
assert(c4 == 49, 'wrong assert #4');

let c5 = dsp.game.get_fuel_consumption(p1, p2, f5);
assert(c5 == 82, 'wrong assert #5');
}

0 comments on commit 69eb412

Please sign in to comment.