some_tester/
some_tester.rs

1#![allow(unused)]
2
3use std::{thread, time::Duration};
4
5use dev_utils::datetime::{Date, DateTime, Time};
6use dev_utils::dlog::set_max_level;
7use dev_utils::format::{Color, Style, Stylize};
8use dev_utils::{app_dt, read_input};
9use std::str::FromStr;
10fn main() {
11    app_dt!(file!());
12    // app_dt!(file!(), "package" => ["license", "keywords"]);
13
14    set_max_level(dev_utils::dlog::Level::Trace);
15
16    // test_io();
17    // test_pause();
18    // f();
19    some();
20}
21
22fn test_io() {
23    let age = read_input::<u32>(Some("Enter your age: ")).unwrap();
24    let name = read_input::<String>(Some("Enter your name: ")).unwrap();
25    println!("Hello, {}! You are {} years old.", name, age);
26}
27
28fn test_pause() {
29    read_input::<i128>(Some("Press Enter to continue...")); // * Input prompt
30    read_input::<String>(None); // * Silent pause
31}
32
33fn f() {
34    let date = Date::new(2023, 5, 1).unwrap();
35    let time = Time::new(12, 34, 56).unwrap();
36    let dt = DateTime { date, time };
37    assert_eq!(dt.to_string(), "2023-05-01 12:34:56");
38    let parsed_dt = DateTime::from_str("2023-05-01 12:34:56").unwrap();
39    assert_eq!(parsed_dt, dt);
40}
41
42fn some() {
43    vec![
44        // vec![src_base, new_base, src, result]
45        // bin -> dec
46        (2, 10, "11011100", "220"),
47        (2, 10, "110011", "51"),
48        (2, 10, "11001100", "204"),
49        (2, 10, "11110011", "243"),
50        (2, 10, "1100111", "103"),
51        // dec -> bin
52        (10, 2, "197", "11000101"),
53        (10, 2, "253", "11111101"),
54        (10, 2, "79", "1001111"),
55        (10, 2, "297", "100101001"),
56        (10, 2, "528", "1000010000"),
57        // bin -> hex
58        (2, 16, "100111011", "13B"),
59        (2, 16, "11011011", "DB"),
60        (2, 16, "101111011", "17B"),
61        (2, 16, "11011001", "D9"),
62        (2, 16, "111011101", "1DD"),
63        // hex -> bin
64        (16, 2, "9F", "10011111"),
65        (16, 2, "9BAF", "1001101110101111"),
66        (16, 2, "8BCD", "1000101111001101"),
67        (16, 2, "72BA", "111001010111010"),
68        (16, 2, "987", "100110000111"),
69        (16, 2, "9F27", "1001111100100111"),
70        // bin -> oct
71        (2, 8, "11011001", "331"),
72        (2, 8, "100111001", "471"),
73        (2, 8, "11100110", "346"),
74        (2, 8, "11001100", "314"),
75        (2, 8, "1101110", "156"),
76        // oct -> bin
77        (8, 2, "245", "10100101"),
78        (8, 2, "327", "11010111"),
79        (8, 2, "651", "110101001"),
80        // ? Decimal numbers test
81        // These aproximate numbers are not exact because of the floating point precision
82        // So the result is not exact, but it's close enough
83        // The str_to_num_from_base() fn returns the last number that is not 0. So the result is not exact
84        // &Example: 0.102000 -> 0.102 (the last 0s are not returned)
85        // TODO: FIX THE DECIMAL PART FUNCTIONS TO COMPARE THIS KIND OF NUMBERS
86        // (10, 2, "450.5", "111000010.1"),
87        // (10, 2, "8.5", "1000.1"),
88        // (10, 8, "450.5", "702.4"),
89        // (10, 8, "7.5", "7.4"),
90        // (10, 16, "450.5", "1C2.8"),
91        // (10, 16, "8.5", "8.8"),
92        // (8, 10, "450.5", "296.625"),
93        // (8, 10, "7.5", "7.625"),
94        // (2, 10, "1010.1", "10.5"),
95        // (20, 6, "AA.21", "550.034050123501235"),
96        // (10, 16, "2197.42", "895.6B851EB851EB851"),
97        // (16, 10, "9E.D", "158.8125"),
98    ]
99    .iter()
100    .for_each(|(src_base, new_base, src, result)| {
101        // dev_utils::info!("{} -> {} (base {})", src, result, new_base);
102        dev_utils::info!(
103            "{:>20} {} -> {:>24} {}",
104            src.style(Style::Bold),
105            format!("(b_{:<02})", src_base.to_string()).style(Style::Dim),
106            result.style(Style::Bold),
107            format!("(b_{:<02})", new_base.to_string()).style(Style::Dim)
108        );
109
110        assert_eq!(
111            dev_utils::base_change::convert_base(src, *src_base, *new_base).unwrap(),
112            *result
113        )
114    });
115}