Skip to content

Commit

Permalink
test(map): add unit tests (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshka committed Aug 26, 2023
1 parent fc9f637 commit f0716ed
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions src/widgets/canvas/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ mod tests {
use strum::ParseError;

use super::*;
use crate::{
assert_buffer_eq,
prelude::*,
widgets::{canvas::Canvas, Widget},
};

#[test]
fn map_resolution_to_string() {
Expand All @@ -62,4 +67,126 @@ mod tests {
Err(ParseError::VariantNotFound)
);
}

#[test]
fn default() {
let map = Map::default();
assert_eq!(map.resolution, MapResolution::Low);
assert_eq!(map.color, Color::Reset);
}

#[test]
fn draw_low() {
let mut buffer = Buffer::empty(Rect::new(0, 0, 80, 40));
let canvas = Canvas::default()
.marker(Marker::Dot)
.x_bounds([-180.0, 180.0])
.y_bounds([-90.0, 90.0])
.paint(|context| {
context.draw(&Map::default());
});
canvas.render(buffer.area, &mut buffer);
let expected = Buffer::with_lines(vec![
" ",
" ••••••• •• •• •• • ",
" •••••••••••••• ••• •••• ••• •• •••• ",
" •••••••••••••••• •• ••• ••••••• •• •• ••• ",
"• • •• •••••• •••••••••••• •• ••• • ••••• ••••••••• •• • • • • ",
"••••• •••• •••••••• •• •• ••• •••• •••• •• • • ",
" •••••••• ••••••• ••••• ••• •••••••• • ••••• ",
" •• •• •• ••••••• •• ••• •••• •• • ",
"••• ••• •••••• •••• •••• •• • •• ",
" • ••••••••• •• • ••• • •• •• •• ",
" • • •••• •• ••••••••• ••• • • • •• ",
" • • ••••• •••• •• •••••• ",
" • •• • • •• • ••••• ",
" •• •• • • •• •• • ",
" •• ••• ••• • • ••••• • ••• ",
" • •••• ••• • • • • • •• ",
" •••• • • •• • • •• •• ",
" ••• •• • • • •• ••• ••• ",
" • • • •• • • • • • ",
" • • • • • • ••• • • ",
" • • • • •• • • • ",
" • • •• ••• • ",
" • • • • • • • • ",
" • • • •• • • • • • ",
" • • • • ",
" • • • • • • ",
" • •• • • • • •• • ",
" • • • •••• •• ",
" • • •• ••• ",
" •• • ",
" •• • ",
" •• ",
" ",
" ••• • •••• • • •• • ",
" •••• •••••• •••••• •••••• • ••• ",
" •• •••••• ••••• •• • ••• • •• ",
"• ••••• •• •• •••••• • •• ",
"• • • • • • • ",
" • ",
" ",
]);
assert_buffer_eq!(buffer, expected);
}

#[test]
fn draw_high() {
let mut buffer = Buffer::empty(Rect::new(0, 0, 80, 40));
let canvas = Canvas::default()
.marker(Marker::Braille)
.x_bounds([-180.0, 180.0])
.y_bounds([-90.0, 90.0])
.paint(|context| {
context.draw(&Map {
resolution: MapResolution::High,
..Default::default()
});
});
canvas.render(buffer.area, &mut buffer);
let expected = Buffer::with_lines(vec![
" ",
" ⢀⣠⠤⠤⠤⠔⢤⣤⡄⠤⡠⣄⠢⠂⢢⠰⣠⡄⣀⡀ ⣀ ",
" ⢀⣀⡤⣦⠲⢶⣿⣮⣿⡉⣰⢶⢏⡂ ⢀⣟⠁ ⢺⣻⢿⠏ ⠈⠉⠁ ⢀⣀ ⠈⠓⢳⣢⣂⡀ ",
" ⡞⣳⣿⣻⡧⣷⣿⣿⢿⢿⣧⡀⠉⠉⠙⢆ ⣰⠇ ⣠⠞⠃⢉⣄⣀⣠⠴⠊⠉⠁ ⠐⠾⠤⢤⠤⡄⠐⣻⠜⢓⠂ ",
"⢍ ⢀⡴⠊⠙⠓⠒⠒⠤⠖⠺⠿⠽⣷⣬⢬⣾⣷⢻⣷⢲⢲⣍⠱⡀ ⠹⡗ ⢀⢐⠟ ⡔⠒⠉⠲⠤⢀⢄⡀⢩⣣⠦⢷⢼⡏⠈ ⠉⠉⠉ ⠈⠈⠉⠖⠤⠆⠒⠭",
"⠶⢽⡲⣽⡆ ⠈⣠⣽⣯⡼⢯⣘⡯⠃⠘⡆ ⢰⠒⠁ ⢾⣚⠟ ⢀⠆ ⣔⠆ ⢷⠾⠋⠁ ⠙⠁ ⠠⡤",
" ⠠⢧⣄⣀⡶⠦⠤⡀ ⢰⡁ ⠉⡻⠙⣎⡥ ⠘⠲⠇ ⢀⡀⠨⣁⡄⣸⢫⡤⠄ ⣀⢠⣤⠊⣼⠅⠖⠋⠁",
" ⣠⠾⠛⠁ ⠈⣱ ⠋⠦⢤⡼ ⠈⠈⠦⡀ ⢀⣿⣇ ⢹⣷⣂⡞⠃ ⢀⣂⡀ ⠏⣜ ",
" ⠙⣷⡄ ⠘⠆ ⢀⣀⡠⣗ ⠘⣻⣽⡟⠉⠈ ⢹⡇ ⠟⠁ ",
" ⠈⡟ ⢎⣻⡿⠾⠇ ⠘⠇ ⣀⡀ ⣤⣤⡆ ⡠⡦ ⢀⠎⡏ ",
" ⡇ ⣀⠏⠋ ⢸⠒⢃⡖⢻⢟⣷⣄⣰⣡⠥⣱ ⢏⣧ ⣀ ⡴⠚⢰⠟ ",
" ⢳ ⢸⠃ ⠸⣄⣼⣠⢼⡴⡟⢿⢿⣀⣄ ⠸⡹ ⠘⡯⢿⡇⡠⢼⠁ ",
" ⢳⣀ ⢀⠞⠁ ⢠⠋⠁ ⠐⠧⡄⣬⣉⣈⡽ ⢧⠘⢽⠟⠉ ",
" ⣿⣄ ⡴⠚⠛⣿⣀ ⢠⠖ ⠈⠁ ⠹⣧ ⢾⣄⡀ ⡼ ⠈ ",
" ⣀ ⠘⣿⡄ ⡇ ⣘⣻ ⡏ ⢻⡄ ⠘⠿⢿⠒⠲⡀ ⢀⡀ ⢀⡰⣗ ",
" ⠉⠷ ⢫⡀⢧⡼⡟⠉⣛⣳⣦⡀ ⠈⡇ ⠸⣱ ⢀⡼ ⢺ ⡸⠉⢇ ⣾⡏ ⣁ ",
" ⠉⠒⢆⡓⡆ ⠠⡃ ⢳⣇⡠⠏ ⠐⡄⡞ ⠘⣇⡀⢱ ⣾⡀ ",
" ⢹⣇⣀⣾⡷⠤⡆ ⢣ ⠯⢺⠇ ⢣⣅ ⣽⢱⡔ ⢠⢿⣗ ",
" ⠙⢱ ⠘⠦⡄ ⠈⢦⡠⣠⢶⣀ ⡜ ⠈⠿ ⢠⣽⢆ ⢀⣼⡜⠿ ",
" ⢀⡞ ⢱⡀ ⢸ ⡔⠁ ⢻⢿⢰⠏⢸⣤⣴⣆ ",
" ⢘⠆ ⠙⠢⢄ ⠸⡀ ⡸⠁ ⠈⣞⡎⠥⡟⣿⠠⠿⣷⠒⢤⢀⣆ ",
" ⠘⠆ ⢈⠂ ⢳ ⡇ ⠈⠳⠶⣤⣭⣠ ⠋⢧⡬⣟⠉⠷⡄ ",
" ⢨ ⡜ ⢸ ⠸ ⣠ ⠁⢁⣰⢶ ⡇⠉⠁ ⠛ ",
"⠆ ⠈⢱⡀ ⡆ ⡇ ⢀⡜⡴⢹ ⢰⠏⠁⠘⢶⠹⡀ ⠸ ⢠⡶",
" ⠅ ⣸ ⢸ ⢫ ⡞⡊ ⢠⠔⠋ ⢳⡀ ⠐⣦ ",
" ⡅ ⡏ ⠈⡆ ⢠⠎ ⠳⠃ ⢸ ⢳ ",
" ⠨ ⡸⠁ ⢱ ⡸ ⠈⡇ ⢀⣀⡀ ⢸ ",
" ⠸ ⠐⡶⠁ ⠘⠖⠚ ⠣⠒⠋ ⠱⣇ ⢀⠇ ⠰⡄ ",
" ⠽ ⣰⡖⠁ ⠘⢚⡊ ⢀⣿⠇",
" ⡯⢀⡟ ⠘⠏ ⢠⢾⠃ ",
" ⠇⢨⠆ ⢠⡄ ⠈⠁ ",
" ⢧⣷⡀⠚ ",
" ⠉⠁ ",
" ⢀⡀ ",
" ⢠⡾⠋ ⣀⡠⠖⢦⣀⣀ ⣀⠤⠦⢤⠤⠶⠤⠖⠦⠤⠤⠤⠴⠤⢤⣄ ",
" ⢀⣤⣀ ⡀ ⣼⣻⠙⡆ ⢀⡤⠤⠤⠴⠒⠖⠒⠒⠒⠚⠉⠋⠁ ⢰⡳⠊⠁ ⠈⠉⠉⠒⠤⣤ ",
" ⢀⣀⣀⡴⠖⠒⠒⠚⠛⠛⠛⠒⠚⠳⠉⠉⠉⠉⢉⣉⡥⠔⠃ ⢀⣠⠤⠴⠃ ⢠⠞⠁ ",
" ⠘⠛⣓⣒⠆ ⠸⠥⣀⣤⡦⠠⣞⣭⣇⣘⠿⠆ ⣖⠛ ",
"⠶⠔⠲⠤⠠⠜⢗⠤⠄ ⠘⠉ ⠁ ⠈⠉⠒⠔⠤",
" ",
]);
assert_buffer_eq!(buffer, expected);
}
}

0 comments on commit f0716ed

Please sign in to comment.