Skip to content

Commit

Permalink
rewrite test for convertor (open-spaced-repetition#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock authored Aug 21, 2023
1 parent eeb7f71 commit d0b0239
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 37 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

17 changes: 10 additions & 7 deletions src/convertor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,23 @@ pub fn anki_to_fsrs() -> Vec<FSRSItem> {
#[test]
fn test() {
let revlogs = read_collection();
dbg!(revlogs.len());
assert_eq!(revlogs.len(), 24394);
let revlogs_per_card = group_by_cid(revlogs);
dbg!(revlogs_per_card.len());
assert_eq!(revlogs_per_card.len(), 3324);
let mut extracted_revlogs_per_card: Vec<Vec<RevlogEntry>> = revlogs_per_card
.into_iter()
.map(|entries| extract_time_series_feature(entries, 4, Tz::Asia__Shanghai))
.collect();

dbg!(&extracted_revlogs_per_card[0]);
extracted_revlogs_per_card = remove_non_learning_first(extracted_revlogs_per_card);
dbg!(extracted_revlogs_per_card
.iter()
.map(|x| x.len())
.sum::<usize>());
assert_eq!(
extracted_revlogs_per_card
.iter()
.map(|x| x.len())
.sum::<usize>(),
17614
);
let fsrs_items: Vec<FSRSItem> = convert_to_fsrs_items(extracted_revlogs_per_card);
dbg!(fsrs_items.len());
assert_eq!(fsrs_items.len(), 14290);
}
26 changes: 0 additions & 26 deletions src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,32 +128,6 @@ impl FSRSDataset {
}
}

#[test]
fn test_from_json() {
const JSON_FILE: &str = "tests/data/revlog_history.json";
use burn::data::dataloader::DataLoaderBuilder;
use burn::data::dataloader::Dataset;
use burn::data::dataset::InMemDataset;
let dataset = InMemDataset::<FSRSItem>::from_json_rows(JSON_FILE).unwrap();
let item = dataset.get(704).unwrap();
dbg!(&item);

use burn_ndarray::NdArrayBackend;
use burn_ndarray::NdArrayDevice;
let device = NdArrayDevice::Cpu;
type Backend = NdArrayBackend<f32>;
let batcher = FSRSBatcher::<Backend>::new(device);
let dataloader = DataLoaderBuilder::new(batcher)
.batch_size(1)
.shuffle(42)
.num_workers(4)
.build(dataset);
for item in dataloader.iter() {
dbg!(&item.r_historys);
break;
}
}

#[test]
fn test_from_anki() {
use burn::data::dataloader::Dataset;
Expand Down
3 changes: 0 additions & 3 deletions tests/data/revlog_history.json

This file was deleted.

0 comments on commit d0b0239

Please sign in to comment.