Skip to content
This repository was archived by the owner on Nov 6, 2024. It is now read-only.

Commit 144fe8f

Browse files
committed
Refactor tests to use 4d stream read test helper
1 parent 56149f9 commit 144fe8f

File tree

3 files changed

+21
-160
lines changed

3 files changed

+21
-160
lines changed

cql_storage_types/cql_i16/tests/i16.rs

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod constants;
22

33
use serial_test::serial;
4-
use std::io::{ Cursor, SeekFrom, Seek };
4+
use std::io::{ Cursor };
55
use constants::DATABASE_LOCATION;
66
use cql_i16::{ I16, unpack_stream };
77

@@ -50,59 +50,13 @@ fn _1d_i16_database_allows_for_stream_reads() {
5050
#[test]
5151
#[serial]
5252
fn _4d_i16_database_allows_for_stream_reads() {
53-
let base_point = [1, 1, 1, 2];
54-
const N_VALUES_TO_READ: usize = 3;
55-
let value1 = 42;
56-
let value2 = 16;
57-
let value3 = 80;
58-
59-
cql_db::create_db_unchecked::<I16>(
60-
DATABASE_LOCATION,
61-
&[1, 1, 1, 10]
62-
).unwrap();
63-
64-
cql_db::link_dimensions_unchecked::<I16>(
53+
cql_storage_type_testing_lib::_4d_database_allows_for_stream_reads::<I16, &dyn Fn(&mut Cursor<Vec<u8>>, usize, &mut [i16])>(
6554
DATABASE_LOCATION,
66-
&base_point[0..3]
67-
).unwrap();
68-
69-
cql_db::write_value_unchecked::<I16>(
70-
DATABASE_LOCATION,
71-
&base_point,
72-
value1
73-
).unwrap();
74-
75-
cql_db::write_value_unchecked::<I16>(
76-
DATABASE_LOCATION,
77-
&[1, 1, 1, base_point[3] + 1],
78-
value2
79-
).unwrap();
80-
81-
cql_db::write_value_unchecked::<I16>(
82-
DATABASE_LOCATION,
83-
&[1, 1, 1, base_point[3] + 2],
84-
value3
85-
).unwrap();
86-
87-
let mut result = [0; N_VALUES_TO_READ];
88-
let mut stream = Cursor::new(Vec::new());
89-
90-
cql_db::read_to_stream_unchecked::<I16>(
91-
DATABASE_LOCATION,
92-
&mut stream,
93-
&base_point,
94-
N_VALUES_TO_READ as u64
95-
).unwrap();
96-
97-
stream.seek(SeekFrom::Start(0)).unwrap();
98-
99-
unpack_stream(&mut stream, N_VALUES_TO_READ, |idx, value| {
100-
result[idx] = value
101-
}).unwrap();
102-
103-
assert_eq!(result[0], value1);
104-
assert_eq!(result[1], value2);
105-
assert_eq!(result[2], value3);
55+
42,
56+
16,
57+
80,
58+
&unpack_i16_stream
59+
);
10660
}
10761

10862
fn unpack_i16_stream (stream: &mut Cursor<Vec<u8>>, n_values: usize, result: &mut [i16]) {

cql_storage_types/cql_nullable_f64/tests/nullable_f64.rs

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod constants;
22

33
use serial_test::serial;
4-
use std::io::{ Cursor, SeekFrom, Seek };
4+
use std::io::{ Cursor };
55
use constants::DATABASE_LOCATION;
66
use cql_nullable_f64::{ NullableF64, unpack_stream };
77

@@ -50,60 +50,13 @@ fn _1d_f64_nullable_database_allows_for_stream_reads() {
5050
#[test]
5151
#[serial]
5252
fn _4d_f64_nullable_database_allows_for_stream_reads() {
53-
let base_point = [1, 1, 1, 2];
54-
const N_VALUES_TO_READ: usize = 4;
55-
let value1 = Some(4.2);
56-
let value2 = Some(1124.6);
57-
let value4 = Some(-0.80);
58-
59-
cql_db::create_db_unchecked::<NullableF64>(
60-
DATABASE_LOCATION,
61-
&[1, 1, 1, 10]
62-
).unwrap();
63-
64-
cql_db::link_dimensions_unchecked::<NullableF64>(
65-
DATABASE_LOCATION,
66-
&base_point[0..3]
67-
).unwrap();
68-
69-
cql_db::write_value_unchecked::<NullableF64>(
70-
DATABASE_LOCATION,
71-
&base_point,
72-
value1
73-
).unwrap();
74-
75-
cql_db::write_value_unchecked::<NullableF64>(
76-
DATABASE_LOCATION,
77-
&[1, 1, 1, base_point[3] + 1],
78-
value2
79-
).unwrap();
80-
81-
cql_db::write_value_unchecked::<NullableF64>(
53+
cql_storage_type_testing_lib::_4d_database_allows_for_stream_reads::<NullableF64, &dyn Fn(&mut Cursor<Vec<u8>>, usize, &mut [Option<f64>])>(
8254
DATABASE_LOCATION,
83-
&[1, 1, 1, base_point[3] + 3],
84-
value4
85-
).unwrap();
86-
87-
let mut result: [Option<f64>; N_VALUES_TO_READ] = [None; N_VALUES_TO_READ];
88-
let mut stream = Cursor::new(Vec::new());
89-
90-
cql_db::read_to_stream_unchecked::<NullableF64>(
91-
DATABASE_LOCATION,
92-
&mut stream,
93-
&base_point,
94-
N_VALUES_TO_READ as u64
95-
).unwrap();
96-
97-
stream.seek(SeekFrom::Start(0)).unwrap();
98-
99-
unpack_stream(&mut stream, N_VALUES_TO_READ, |idx, value| {
100-
result[idx] = value
101-
}).unwrap();
102-
103-
assert_eq!(result[0], value1);
104-
assert_eq!(result[1], value2);
105-
assert_eq!(result[2], None);
106-
assert_eq!(result[3], value4);
55+
Some(4.2),
56+
Some(1124.6),
57+
Some(-0.80),
58+
&unpack_nullable_f64_stream
59+
);
10760
}
10861

10962
fn unpack_nullable_f64_stream (stream: &mut Cursor<Vec<u8>>, n_values: usize, result: &mut [Option<f64>]) {

cql_storage_types/cql_u64/tests/u64.rs

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod constants;
22

33
use serial_test::serial;
4-
use std::io::{ Cursor, SeekFrom, Seek };
4+
use std::io::{ Cursor };
55
use constants::DATABASE_LOCATION;
66
use cql_u64::{ U64, unpack_stream };
77

@@ -50,59 +50,13 @@ fn _1d_u64_database_allows_for_stream_reads() {
5050
#[test]
5151
#[serial]
5252
fn _4d_u64_database_allows_for_stream_reads() {
53-
let base_point = [1, 1, 1, 2];
54-
const N_VALUES_TO_READ: usize = 3;
55-
let value1 = 42;
56-
let value2 = 16;
57-
let value3 = 80;
58-
59-
cql_db::create_db_unchecked::<U64>(
60-
DATABASE_LOCATION,
61-
&[1, 1, 1, 10]
62-
).unwrap();
63-
64-
cql_db::link_dimensions_unchecked::<U64>(
53+
cql_storage_type_testing_lib::_4d_database_allows_for_stream_reads::<U64, &dyn Fn(&mut Cursor<Vec<u8>>, usize, &mut [u64])>(
6554
DATABASE_LOCATION,
66-
&base_point[0..3]
67-
).unwrap();
68-
69-
cql_db::write_value_unchecked::<U64>(
70-
DATABASE_LOCATION,
71-
&base_point,
72-
value1
73-
).unwrap();
74-
75-
cql_db::write_value_unchecked::<U64>(
76-
DATABASE_LOCATION,
77-
&[1, 1, 1, base_point[3] + 1],
78-
value2
79-
).unwrap();
80-
81-
cql_db::write_value_unchecked::<U64>(
82-
DATABASE_LOCATION,
83-
&[1, 1, 1, base_point[3] + 2],
84-
value3
85-
).unwrap();
86-
87-
let mut result = [0; N_VALUES_TO_READ];
88-
let mut stream = Cursor::new(Vec::new());
89-
90-
cql_db::read_to_stream_unchecked::<U64>(
91-
DATABASE_LOCATION,
92-
&mut stream,
93-
&base_point,
94-
N_VALUES_TO_READ as u64
95-
).unwrap();
96-
97-
stream.seek(SeekFrom::Start(0)).unwrap();
98-
99-
unpack_stream(&mut stream, N_VALUES_TO_READ, |idx, value| {
100-
result[idx] = value
101-
}).unwrap();
102-
103-
assert_eq!(result[0], value1);
104-
assert_eq!(result[1], value2);
105-
assert_eq!(result[2], value3);
55+
42,
56+
16,
57+
80,
58+
&unpack_u64_stream
59+
);
10660
}
10761

10862
fn unpack_u64_stream (stream: &mut Cursor<Vec<u8>>, n_values: usize, result: &mut [u64]) {

0 commit comments

Comments
 (0)