generate_test_data/
generate-test-data.rs1use relevancy::{
6 url_hash::{hash_url, UrlHash},
7 Interest,
8};
9use std::{collections::HashMap, fs::File, io::Write};
10
11const TEST_INTEREST_DATA: &[(&str, Interest)] = &[
16 ("https://espn.com/", Interest::Sports),
17 ("https://dogs.com/", Interest::Animals),
18 ("https://cars.com/", Interest::Autos),
19 ("https://www.vouge.com/", Interest::Fashion),
20 ("https://slashdot.org/", Interest::Tech),
21 ("https://www.nascar.com/", Interest::Autos),
22 ("https://www.nascar.com/", Interest::Sports),
23];
24
25fn main() {
26 let mut interest_map: HashMap<Interest, Vec<UrlHash>> =
27 HashMap::from_iter(Interest::all().into_iter().map(|i| (i, vec![])));
28 for (url, interest) in TEST_INTEREST_DATA {
29 if let Some(hash) = hash_url(url) {
30 interest_map.get_mut(interest).unwrap().push(hash)
31 }
32 }
33
34 let mut f = File::create("test-data").expect("Error opening file");
35 for interest in Interest::all() {
37 let hashes = interest_map.get(&interest).unwrap();
39 f.write_all(&(hashes.len() as u32).to_le_bytes())
41 .expect("Error writing file");
42 for hash in hashes {
44 f.write_all(hash).expect("Error writing file");
45 }
46 }
47}