Skip to content

Commit

Permalink
✅ Update test to remove length
Browse files Browse the repository at this point in the history
  • Loading branch information
bal7hazar committed Sep 9, 2024
1 parent 82d95b3 commit cf5b245
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions crates/pathfinding/src/helpers/astar.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub impl Astar of AstarTrait {
path.append(current.position);
current = heap.at(current.source);
};
println!("path: {:?}", path);

// [Return] The path from the start to the target
path.span()
Expand Down Expand Up @@ -137,32 +138,30 @@ mod test {

#[test]
fn test_astar_search_small() {
// x 1 1
// 1 0 1
// x───┐
// 1 0
// 0 1 s
let grid: felt252 = 0x1EB;
let width = 3;
let height = 3;
let from = 0;
let to = 8;
let mut path = Astar::search(grid, width, height, from, to);
assert_eq!(path.len(), 4);
assert_eq!(path, array![8, 7, 6, 3].span());
}

#[test]
fn test_astar_search_medium() {
// 1 x 0 0
// 1 0 1 1
// 1 1 1 1
// ┌─x 0 0
// 0 1 1
// └─────┐
// 1 1 1 s
let grid: felt252 = 0xCBFF;
let width = 4;
let height = 4;
let from = 0;
let to = 14;
let mut path = Astar::search(grid, width, height, from, to);
assert_eq!(path.len(), 7);
assert_eq!(path, array![14, 15, 11, 7, 6, 5, 4].span());
}

Expand All @@ -180,14 +179,41 @@ mod test {
// 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 │ 0
// 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 │ 0
// 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 │ 0
// 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 x 0
// 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 s 0
// 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
let grid: felt252 = 0x7F003F800FB001FC003C481F1F0FFFE1EEF83FFE1FFF81FFE03FF80000;
let width = 18;
let height = 14;
let from = 19;
let to = 224;
let mut path = Astar::search(grid, width, height, from, to);
assert_eq!(path.len(), 22);
assert_eq!(
path,
array![
224,
225,
207,
189,
171,
172,
154,
136,
118,
117,
116,
115,
114,
113,
112,
94,
93,
75,
57,
56,
55,
37
]
.span()
);
}
}

0 comments on commit cf5b245

Please sign in to comment.