Get back to basics, with some basic tests working.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#![no_std]
|
||||
#![cfg_attr(not(test),no_std)]
|
||||
pub mod signed;
|
||||
pub mod unsigned;
|
||||
#[cfg(test)]
|
||||
mod testing;
|
||||
|
||||
/// A trait definition for large numbers.
|
||||
pub trait CryptoNum {
|
||||
@@ -25,7 +27,7 @@ pub trait CryptoNum {
|
||||
/// this will assume that the number is in the first `n` bits of the
|
||||
/// memory layout. If you pass in a smaller buffer, it will use the bits
|
||||
/// available as the low `n` bits of the number.
|
||||
fn from_bytes(&self, bytes: &[u8]) -> Self;
|
||||
fn from_bytes(bytes: &[u8]) -> Self;
|
||||
/// Write the cryptonum into the provide slice. If the provided slice
|
||||
/// is greater than or equal to `n` bits in length, `to_bytes` will
|
||||
/// write to the first `n` bits. If the slice is less than `n` bits
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::str::Lines;
|
||||
|
||||
pub fn build_test_path(dir: &str, typename: &str) -> String
|
||||
pub fn build_test_path(dir: &str, typename: &str) -> PathBuf
|
||||
{
|
||||
let mut name = typename.to_string();
|
||||
name.remove(0);
|
||||
while name.len() < 5 {
|
||||
name.insert(0, '0');
|
||||
}
|
||||
format!("testdata/{}/{}.test", dir, name)
|
||||
let mut res = PathBuf::new();
|
||||
res.push(".");
|
||||
res.push("testdata");
|
||||
res.push(dir);
|
||||
res.push(typename);
|
||||
res.set_extension("test");
|
||||
res
|
||||
}
|
||||
|
||||
fn next_value_set(line: &str) -> (String, bool, Vec<u8>)
|
||||
@@ -58,9 +60,10 @@ fn next_test_case(contents: &mut Lines, lines: usize) ->
|
||||
Some(res)
|
||||
}
|
||||
|
||||
pub fn run_test<F>(fname: String, i: usize, f: F)
|
||||
pub fn run_test<F>(fname: PathBuf, i: usize, f: F)
|
||||
where F: Fn(HashMap<String,(bool,Vec<u8>)>)
|
||||
{
|
||||
println!("fname: {:?}", fname);
|
||||
let mut file = File::open(fname).unwrap();
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user