From 66f5b0984946e935c9df10024926061ea5ea83d9 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Wed, 8 May 2024 22:03:16 +0200 Subject: [PATCH] add correctness check --- lab3/zad1/rand_select/src/main.rs | 4 +++- lab3/zad1/select/src/main.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lab3/zad1/rand_select/src/main.rs b/lab3/zad1/rand_select/src/main.rs index 0eeb106..89769f7 100644 --- a/lab3/zad1/rand_select/src/main.rs +++ b/lab3/zad1/rand_select/src/main.rs @@ -47,7 +47,8 @@ fn main() -> io::Result<()> { println!("start state: {:?}", input_list); println!("end state: {:?}", list); let mut insertion = InsertionSort::new(false); - println!("sorted array: {:?}", insertion.sort(&input_list)); + let sorted = insertion.sort(&input_list); + println!("sorted array: {:?}", sorted); let ordinal_indicator = match order_statistic { 1 => "st", 2 => "nd", @@ -55,6 +56,7 @@ fn main() -> io::Result<()> { _ => "th", }; println!("{}{} order statistic: {}", order_statistic, ordinal_indicator, result); + println!("is correct: {}", result == sorted[order_statistic - 1]); } println!("swaps: {}", randomized.num_swap()); diff --git a/lab3/zad1/select/src/main.rs b/lab3/zad1/select/src/main.rs index 40f132c..fd84f58 100644 --- a/lab3/zad1/select/src/main.rs +++ b/lab3/zad1/select/src/main.rs @@ -47,7 +47,8 @@ fn main() -> io::Result<()> { println!("start state: {:?}", input_list); println!("end state: {:?}", list); let mut insertion = InsertionSort::new(false); - println!("sorted array: {:?}", insertion.sort(&input_list)); + let sorted = insertion.sort(&input_list); + println!("sorted array: {:?}", sorted); let ordinal_indicator = match order_statistic { 1 => "st", 2 => "nd", @@ -55,6 +56,7 @@ fn main() -> io::Result<()> { _ => "th", }; println!("{}{} order statistic: {}", order_statistic, ordinal_indicator, result); + println!("is correct: {}", result == sorted[order_statistic - 1]); } println!("swaps: {}", normal.num_swap());