Skip to content

Commit 2d4cb5c

Browse files
authored
improve test coverage (#26)
* add some tests * fix doc-tests * switch to llvm-cov
1 parent 2710f7a commit 2d4cb5c

File tree

4 files changed

+58
-13
lines changed

4 files changed

+58
-13
lines changed

.github/workflows/coverage.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ jobs:
1919
toolchain: nightly
2020
profile: minimal
2121
override: true
22+
components: llvm-tools-preview
2223

23-
- name: Run cargo-tarpaulin
24-
uses: actions-rs/[email protected]
25-
with:
26-
args: --all-features --tests --doc
24+
- name: Install cargo-llvm-cov
25+
uses: taiki-e/install-action@cargo-llvm-cov
26+
27+
- name: Run llvm-cov
28+
run: cargo llvm-cov --all-features --doctests --workspace --lcov --output-path lcov.info
2729

28-
- name: Upload to codecov.io
29-
uses: codecov/codecov-action@v2.1.0
30+
- name: Upload coverage to Codecov
31+
uses: codecov/codecov-action@v2
3032
with:
31-
token: ${{secrets.CODECOV_TOKEN}}
33+
files: lcov.info

arithmetic-coding-core/src/fixed_length.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use crate::BitStore;
2020
/// ```
2121
/// #![feature(exclusive_range_pattern)]
2222
/// #![feature(never_type)]
23-
/// use std::ops::Range;
24-
///
25-
/// use arithmetic_coding::fixed_length;
23+
/// # use std::ops::Range;
24+
/// #
25+
/// # use arithmetic_coding_core::fixed_length;
2626
///
2727
/// pub enum Symbol {
2828
/// A,

arithmetic-coding-core/src/model.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use crate::BitStore;
1313
/// ```
1414
/// #![feature(exclusive_range_pattern)]
1515
/// #![feature(never_type)]
16-
/// use std::ops::Range;
17-
///
18-
/// use arithmetic_coding::Model;
16+
/// # use std::ops::Range;
17+
/// #
18+
/// # use arithmetic_coding_core::Model;
1919
///
2020
/// pub enum Symbol {
2121
/// A,

fenwick-model/src/lib.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,46 @@ impl Weights {
7979
#[derive(Debug, thiserror::Error)]
8080
#[error("invalid symbol received: {0}")]
8181
pub struct ValueError(pub usize);
82+
83+
#[cfg(test)]
84+
mod tests {
85+
use super::Weights;
86+
87+
#[test]
88+
fn total() {
89+
let weights = Weights::new(3);
90+
assert_eq!(weights.total(), 4);
91+
}
92+
93+
#[test]
94+
fn range() {
95+
let weights = Weights::new(3);
96+
assert_eq!(weights.range(None), 0..1);
97+
assert_eq!(weights.range(Some(0)), 1..2);
98+
assert_eq!(weights.range(Some(1)), 2..3);
99+
assert_eq!(weights.range(Some(2)), 3..4);
100+
}
101+
102+
#[test]
103+
#[should_panic]
104+
fn range_out_of_bounds() {
105+
let weights = Weights::new(3);
106+
weights.range(Some(3));
107+
}
108+
109+
#[test]
110+
fn symbol() {
111+
let weights = Weights::new(3);
112+
assert_eq!(weights.symbol(0), None);
113+
assert_eq!(weights.symbol(1), Some(0));
114+
assert_eq!(weights.symbol(2), Some(1));
115+
assert_eq!(weights.symbol(3), Some(2));
116+
}
117+
118+
#[test]
119+
#[should_panic]
120+
fn symbol_out_of_bounds() {
121+
let weights = Weights::new(3);
122+
weights.symbol(4);
123+
}
124+
}

0 commit comments

Comments
 (0)