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

Commit e823d4e

Browse files
authored
Merge pull request #41 from AndrewSisley/testRefactoring
Integration test refactoring
2 parents e94c019 + 144fe8f commit e823d4e

File tree

9 files changed

+387
-710
lines changed

9 files changed

+387
-710
lines changed

cql_storage_types/cql_i16/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ path = "src/i16.rs"
1717
[dev-dependencies]
1818
cql_db = "^0.2.4"
1919
serial_test = "0.3.2"
20+
cql_storage_type_testing_lib = "^0.2.0"
2021

2122
[dependencies]
2223
cql_model = "^0.2"
Lines changed: 29 additions & 242 deletions
Original file line numberDiff line numberDiff line change
@@ -1,279 +1,66 @@
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

88
#[test]
99
#[serial]
1010
fn _1d_i16_database_allows_for_single_point_read_writes() {
11-
let axis = [
12-
2,
13-
];
14-
15-
let point1 = [2];
16-
let value1 = 42;
17-
18-
cql_db::create_db_unchecked::<I16>(
19-
DATABASE_LOCATION,
20-
&axis
21-
).unwrap();
22-
23-
cql_db::write_value_unchecked::<I16>(
24-
DATABASE_LOCATION,
25-
&point1,
26-
value1
27-
).unwrap();
28-
29-
let result1 = cql_db::read_value_unchecked::<I16>(
11+
cql_storage_type_testing_lib::_1d_database_allows_for_single_point_read_writes::<I16>(
3012
DATABASE_LOCATION,
31-
&point1
32-
).unwrap();
33-
34-
assert_eq!(result1, value1);
13+
42
14+
);
3515
}
3616

3717
#[test]
3818
#[serial]
3919
fn _4d_i16_database_allows_for_single_point_read_writes() {
40-
let axis = [
41-
2,
42-
5,
43-
3,
44-
2,
45-
];
46-
47-
let point1 = [2, 4, 3, 1];
48-
let value1 = 5;
49-
50-
cql_db::create_db_unchecked::<I16>(
20+
cql_storage_type_testing_lib::_4d_database_allows_for_single_point_read_writes::<I16>(
5121
DATABASE_LOCATION,
52-
&axis
53-
).unwrap();
54-
55-
cql_db::link_dimensions_unchecked::<I16>(
56-
DATABASE_LOCATION,
57-
&point1[0..3],
58-
).unwrap();
59-
60-
cql_db::write_value_unchecked::<I16>(
61-
DATABASE_LOCATION,
62-
&point1,
63-
value1
64-
).unwrap();
65-
66-
let result1 = cql_db::read_value_unchecked::<I16>(
67-
DATABASE_LOCATION,
68-
&point1
69-
).unwrap();
70-
71-
assert_eq!(result1, value1);
22+
5
23+
);
7224
}
7325

7426
#[test]
7527
#[serial]
7628
fn _4d_i16_database_allows_for_single_point_read_writes_given_multiple_values_and_overwrites() {
77-
let axis = [
78-
2,
79-
5,
80-
3,
81-
4,
82-
];
83-
84-
let point1 = [2, 4, 3, 1];
85-
let point2 = [1, 4, 3, 1];
86-
let point3 = [2, 1, 3, 1];
87-
let point4 = [2, 4, 3, 2];
88-
let value1 = 5;
89-
let value2 = -20;
90-
let value3 = 0;
91-
let value5 = 30000;
92-
93-
cql_db::create_db_unchecked::<I16>(
94-
DATABASE_LOCATION,
95-
&axis
96-
).unwrap();
97-
98-
cql_db::link_dimensions_unchecked::<I16>(
99-
DATABASE_LOCATION,
100-
&point1[0..3]
101-
).unwrap();
102-
103-
cql_db::link_dimensions_unchecked::<I16>(
104-
DATABASE_LOCATION,
105-
&point2[0..3]
106-
).unwrap();
107-
108-
cql_db::link_dimensions_unchecked::<I16>(
109-
DATABASE_LOCATION,
110-
&point3[0..3]
111-
).unwrap();
112-
113-
cql_db::write_value_unchecked::<I16>(
114-
DATABASE_LOCATION,
115-
&point1,
116-
value1
117-
).unwrap();
118-
119-
cql_db::write_value_unchecked::<I16>(
120-
DATABASE_LOCATION,
121-
&point2,
122-
value2
123-
).unwrap();
124-
125-
cql_db::write_value_unchecked::<I16>(
126-
DATABASE_LOCATION,
127-
&point3,
128-
value3
129-
).unwrap();
130-
131-
let result1 = cql_db::read_value_unchecked::<I16>(
132-
DATABASE_LOCATION,
133-
&point1
134-
).unwrap();
135-
136-
let result2 = cql_db::read_value_unchecked::<I16>(
137-
DATABASE_LOCATION,
138-
&point2
139-
).unwrap();
140-
141-
let result3 = cql_db::read_value_unchecked::<I16>(
29+
cql_storage_type_testing_lib::_4d_database_allows_for_single_point_read_writes_given_multiple_values_and_overwrites::<I16>(
14230
DATABASE_LOCATION,
143-
&point3
144-
).unwrap();
145-
146-
let result4 = cql_db::read_value_unchecked::<I16>(
147-
DATABASE_LOCATION,
148-
&point4
149-
).unwrap();
150-
151-
assert_eq!(result1, value1);
152-
assert_eq!(result2, value2);
153-
assert_eq!(result3, value3);
154-
assert_eq!(result4, 0);
155-
156-
cql_db::write_value_unchecked::<I16>(
157-
DATABASE_LOCATION,
158-
&point2,
159-
value5
160-
).unwrap();
161-
162-
let result5 = cql_db::read_value_unchecked::<I16>(
163-
DATABASE_LOCATION,
164-
&point2
165-
).unwrap();
166-
167-
assert_eq!(result5, value5);
31+
5,
32+
-20,
33+
0,
34+
30000
35+
);
16836
}
16937

17038
#[test]
17139
#[serial]
17240
fn _1d_i16_database_allows_for_stream_reads() {
173-
let base_point = [2];
174-
const N_VALUES_TO_READ: usize = 3;
175-
let value1 = 42;
176-
let value2 = 16;
177-
let value3 = 80;
178-
179-
cql_db::create_db_unchecked::<I16>(
180-
DATABASE_LOCATION,
181-
&[10]
182-
).unwrap();
183-
184-
cql_db::write_value_unchecked::<I16>(
185-
DATABASE_LOCATION,
186-
&base_point,
187-
value1
188-
).unwrap();
189-
190-
cql_db::write_value_unchecked::<I16>(
191-
DATABASE_LOCATION,
192-
&[base_point[0] + 1],
193-
value2
194-
).unwrap();
195-
196-
cql_db::write_value_unchecked::<I16>(
197-
DATABASE_LOCATION,
198-
&[base_point[0] + 2],
199-
value3
200-
).unwrap();
201-
202-
let mut result = [0; N_VALUES_TO_READ];
203-
let mut stream = Cursor::new(Vec::new());
204-
205-
cql_db::read_to_stream_unchecked::<I16>(
41+
cql_storage_type_testing_lib::_1d_database_allows_for_stream_reads::<I16, &dyn Fn(&mut Cursor<Vec<u8>>, usize, &mut [i16])>(
20642
DATABASE_LOCATION,
207-
&mut stream,
208-
&base_point,
209-
N_VALUES_TO_READ as u64
210-
).unwrap();
211-
212-
stream.seek(SeekFrom::Start(0)).unwrap();
213-
214-
unpack_stream(&mut stream, N_VALUES_TO_READ, |idx, value| {
215-
result[idx] = value
216-
}).unwrap();
217-
218-
assert_eq!(result[0], value1);
219-
assert_eq!(result[1], value2);
220-
assert_eq!(result[2], value3);
43+
42,
44+
16,
45+
80,
46+
&unpack_i16_stream
47+
);
22148
}
22249

22350
#[test]
22451
#[serial]
22552
fn _4d_i16_database_allows_for_stream_reads() {
226-
let base_point = [1, 1, 1, 2];
227-
const N_VALUES_TO_READ: usize = 3;
228-
let value1 = 42;
229-
let value2 = 16;
230-
let value3 = 80;
231-
232-
cql_db::create_db_unchecked::<I16>(
53+
cql_storage_type_testing_lib::_4d_database_allows_for_stream_reads::<I16, &dyn Fn(&mut Cursor<Vec<u8>>, usize, &mut [i16])>(
23354
DATABASE_LOCATION,
234-
&[1, 1, 1, 10]
235-
).unwrap();
236-
237-
cql_db::link_dimensions_unchecked::<I16>(
238-
DATABASE_LOCATION,
239-
&base_point[0..3]
240-
).unwrap();
241-
242-
cql_db::write_value_unchecked::<I16>(
243-
DATABASE_LOCATION,
244-
&base_point,
245-
value1
246-
).unwrap();
247-
248-
cql_db::write_value_unchecked::<I16>(
249-
DATABASE_LOCATION,
250-
&[1, 1, 1, base_point[3] + 1],
251-
value2
252-
).unwrap();
253-
254-
cql_db::write_value_unchecked::<I16>(
255-
DATABASE_LOCATION,
256-
&[1, 1, 1, base_point[3] + 2],
257-
value3
258-
).unwrap();
259-
260-
let mut result = [0; N_VALUES_TO_READ];
261-
let mut stream = Cursor::new(Vec::new());
262-
263-
cql_db::read_to_stream_unchecked::<I16>(
264-
DATABASE_LOCATION,
265-
&mut stream,
266-
&base_point,
267-
N_VALUES_TO_READ as u64
268-
).unwrap();
269-
270-
stream.seek(SeekFrom::Start(0)).unwrap();
55+
42,
56+
16,
57+
80,
58+
&unpack_i16_stream
59+
);
60+
}
27161

272-
unpack_stream(&mut stream, N_VALUES_TO_READ, |idx, value| {
62+
fn unpack_i16_stream (stream: &mut Cursor<Vec<u8>>, n_values: usize, result: &mut [i16]) {
63+
unpack_stream(stream, n_values, |idx, value| {
27364
result[idx] = value
274-
}).unwrap();
275-
276-
assert_eq!(result[0], value1);
277-
assert_eq!(result[1], value2);
278-
assert_eq!(result[2], value3);
65+
}).unwrap()
27966
}

cql_storage_types/cql_nullable_f64/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ path = "src/nullable_f64.rs"
1717
[dev-dependencies]
1818
cql_db = "^0.2"
1919
serial_test = "0.3.2"
20+
cql_storage_type_testing_lib = "^0.2.0"
2021

2122
[dependencies]
2223
cql_model = "^0.2"

0 commit comments

Comments
 (0)