bin/darkfid: float->u64 conversion test case

This commit is contained in:
lunar-mining
2021-09-28 10:20:46 +02:00
parent 5c12623b95
commit 2b0dc655c6

View File

@@ -432,20 +432,47 @@ async fn main() -> Result<()> {
mod tests {
#[test]
fn test_token_parsing() {
let token = "usdc";
//#[test]
//fn test_token_parsing() {
// let token = "usdc";
let vec: Vec<char> = token.chars().collect();
let mut counter = 0;
for c in vec {
if c.is_alphabetic() {
counter += 1;
println!("Found letter: {}", c)
// let vec: Vec<char> = token.chars().collect();
// let mut counter = 0;
// for c in vec {
// if c.is_alphabetic() {
// counter += 1;
// println!("Found letter: {}", c)
// }
// }
// if counter == token.len() {
// println!("Every character is a letter");
// }
//}
// using byte repr produces this u64: 4592670019360778722
//
//let float_bytes = float.to_ne_bytes();
//let u64_bytes = u64::from_ne_bytes(float_bytes);
//println!("U64 FROM NE BYTES {:?}", u64_bytes);
#[test]
fn test_float_transform() {
println!("TEST FLOAT TRANSFORM");
let float: f64 = 0.1111;
let mut float_str = float.to_string();
println!("FLOAT TO STRING: {}", float_str);
match float_str.find(".") {
Some(v) => {
float_str.remove(v);
print!("FLOAT WITH DECIMAL REMOVED: {} \n", float_str);
const RADIX: u32 = 10;
for i in float_str.chars() {
let digit = i.to_digit(RADIX).unwrap();
println!("TO RADIX CONVERSION: {}", digit);
}
}
None => {
print!("NO FLOAT DETECTED");
}
}
if counter == token.len() {
println!("Every character is a letter");
}
}
}