2018-09-29 10:41:00 +00:00
|
|
|
#![cfg(test)]
|
|
|
|
|
2018-09-29 08:50:08 +00:00
|
|
|
use crate::implementation::QueryContextImpl;
|
|
|
|
use crate::queries::QueryContext;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn memoized_twice() {
|
|
|
|
let query = QueryContextImpl::default();
|
2018-09-30 14:59:08 +00:00
|
|
|
let v1 = query.memoized().read();
|
|
|
|
let v2 = query.memoized().read();
|
2018-09-29 08:50:08 +00:00
|
|
|
assert_eq!(v1, v2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2018-09-30 10:09:37 +00:00
|
|
|
fn volatile_twice() {
|
2018-09-29 08:50:08 +00:00
|
|
|
let query = QueryContextImpl::default();
|
2018-09-30 14:59:08 +00:00
|
|
|
let v1 = query.volatile().read();
|
|
|
|
let v2 = query.volatile().read();
|
2018-09-29 08:50:08 +00:00
|
|
|
assert_eq!(v1 + 1, v2);
|
|
|
|
}
|
2018-09-29 08:53:59 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn intermingled() {
|
|
|
|
let query = QueryContextImpl::default();
|
2018-09-30 14:59:08 +00:00
|
|
|
let v1 = query.volatile().read();
|
|
|
|
let v2 = query.memoized().read();
|
|
|
|
let v3 = query.volatile().read();
|
|
|
|
let v4 = query.memoized().read();
|
2018-09-29 08:53:59 +00:00
|
|
|
|
|
|
|
assert_eq!(v1 + 1, v2);
|
|
|
|
assert_eq!(v2 + 1, v3);
|
|
|
|
assert_eq!(v2, v4);
|
|
|
|
}
|