Skip to main content

klirr_core/models/
cost.rs

1use crate::prelude::*;
2
3/// The total cost of an item, e.g. the total cost of a consulting service.
4/// Being the quantity multiplied by the unit price.
5#[derive(
6    Clone, Copy, Display, Debug, PartialEq, Eq, Hash, Default, Serialize, Deserialize, From, Deref,
7)]
8#[from(forward)]
9#[deref(forward)]
10pub struct Cost(Decimal);
11
12impl HasSample for Cost {
13    fn sample() -> Self {
14        Self::from(dec!(350.0))
15    }
16    fn sample_other() -> Self {
17        Self::from(dec!(500.0))
18    }
19}
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24
25    type Sut = Cost;
26
27    #[test]
28    fn equality() {
29        assert_eq!(Sut::sample(), Sut::sample());
30        assert_eq!(Sut::sample_other(), Sut::sample_other());
31    }
32
33    #[test]
34    fn inequality() {
35        assert_ne!(Sut::sample(), Sut::sample_other());
36    }
37}