Skip to content

Commit 18c868a

Browse files
author
andrei-papou
committed
PRINT_ELEMENTS_LIMIT is now private
1 parent 0d11708 commit 18c868a

File tree

3 files changed

+129
-129
lines changed

3 files changed

+129
-129
lines changed

src/arrayformat.rs

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::{
1515
};
1616
use crate::dimension::IntoDimension;
1717

18-
pub const PRINT_ELEMENTS_LIMIT: Ix = 3;
18+
const PRINT_ELEMENTS_LIMIT: Ix = 3;
1919

2020
fn format_array_v2<A, S, D, F>(view: &ArrayBase<S, D>,
2121
f: &mut fmt::Formatter,
@@ -291,3 +291,130 @@ impl<'a, A: fmt::Binary, S, D: Dimension> fmt::Binary for ArrayBase<S, D>
291291
format_array_v2(self, f, <_>::fmt, PRINT_ELEMENTS_LIMIT)
292292
}
293293
}
294+
295+
#[cfg(test)]
296+
mod formatting_with_omit {
297+
use crate::prelude::*;
298+
use super::*;
299+
300+
fn print_output_diff(expected: &str, actual: &str) {
301+
println!("Expected output:\n{}\nActual output:\n{}", expected, actual);
302+
}
303+
304+
#[test]
305+
fn dim_1() {
306+
let overflow: usize = 5;
307+
let a = Array1::from_elem((PRINT_ELEMENTS_LIMIT * 2 + overflow, ), 1);
308+
let mut expected_output = String::from("[");
309+
a.iter()
310+
.take(PRINT_ELEMENTS_LIMIT)
311+
.for_each(|elem| { expected_output.push_str(format!("{}, ", elem).as_str()) });
312+
expected_output.push_str("...");
313+
a.iter()
314+
.skip(PRINT_ELEMENTS_LIMIT + overflow)
315+
.for_each(|elem| { expected_output.push_str(format!(", {}", elem).as_str()) });
316+
expected_output.push(']');
317+
let actual_output = format!("{}", a);
318+
319+
print_output_diff(&expected_output, &actual_output);
320+
assert_eq!(actual_output, expected_output);
321+
}
322+
323+
#[test]
324+
fn dim_2_last_axis_overflow() {
325+
let overflow: usize = 3;
326+
let a = Array2::from_elem((PRINT_ELEMENTS_LIMIT, PRINT_ELEMENTS_LIMIT * 2 + overflow), 1);
327+
let mut expected_output = String::from("[");
328+
329+
for i in 0..PRINT_ELEMENTS_LIMIT {
330+
expected_output.push_str(format!("[{}", a[(i, 0)]).as_str());
331+
for j in 1..PRINT_ELEMENTS_LIMIT {
332+
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
333+
}
334+
expected_output.push_str(", ...");
335+
for j in PRINT_ELEMENTS_LIMIT + overflow..PRINT_ELEMENTS_LIMIT * 2 + overflow {
336+
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
337+
}
338+
expected_output.push_str(if i < PRINT_ELEMENTS_LIMIT - 1 { "],\n " } else { "]" });
339+
}
340+
expected_output.push(']');
341+
let actual_output = format!("{}", a);
342+
343+
print_output_diff(&expected_output, &actual_output);
344+
assert_eq!(actual_output, expected_output);
345+
}
346+
347+
#[test]
348+
fn dim_2_non_last_axis_overflow() {
349+
let overflow: usize = 5;
350+
let a = Array2::from_elem((PRINT_ELEMENTS_LIMIT * 2 + overflow, PRINT_ELEMENTS_LIMIT), 1);
351+
let mut expected_output = String::from("[");
352+
353+
for i in 0..PRINT_ELEMENTS_LIMIT {
354+
expected_output.push_str(format!("[{}", a[(i, 0)]).as_str());
355+
for j in 1..PRINT_ELEMENTS_LIMIT {
356+
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
357+
}
358+
expected_output.push_str("],\n ");
359+
}
360+
expected_output.push_str("...,\n ");
361+
for i in PRINT_ELEMENTS_LIMIT + overflow..PRINT_ELEMENTS_LIMIT * 2 + overflow {
362+
expected_output.push_str(format!("[{}", a[(i, 0)]).as_str());
363+
for j in 1..PRINT_ELEMENTS_LIMIT {
364+
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
365+
}
366+
expected_output.push_str(if i == PRINT_ELEMENTS_LIMIT * 2 + overflow - 1 {
367+
"]"
368+
} else {
369+
"],\n "
370+
});
371+
}
372+
expected_output.push(']');
373+
let actual_output = format!("{}", a);
374+
375+
print_output_diff(&expected_output, &actual_output);
376+
assert_eq!(actual_output, expected_output);
377+
}
378+
379+
#[test]
380+
fn dim_2_multi_directional_overflow() {
381+
let overflow: usize = 5;
382+
let a = Array2::from_elem(
383+
(PRINT_ELEMENTS_LIMIT * 2 + overflow, PRINT_ELEMENTS_LIMIT * 2 + overflow), 1
384+
);
385+
let mut expected_output = String::from("[");
386+
387+
for i in 0..PRINT_ELEMENTS_LIMIT {
388+
expected_output.push_str(format!("[{}", a[(i, 0)]).as_str());
389+
for j in 1..PRINT_ELEMENTS_LIMIT {
390+
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
391+
}
392+
expected_output.push_str(", ...");
393+
for j in PRINT_ELEMENTS_LIMIT + overflow..PRINT_ELEMENTS_LIMIT * 2 + overflow {
394+
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
395+
}
396+
expected_output.push_str("],\n ");
397+
}
398+
expected_output.push_str("...,\n ");
399+
for i in PRINT_ELEMENTS_LIMIT + overflow..PRINT_ELEMENTS_LIMIT * 2 + overflow {
400+
expected_output.push_str(format!("[{}", a[(i, 0)]).as_str());
401+
for j in 1..PRINT_ELEMENTS_LIMIT {
402+
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
403+
}
404+
expected_output.push_str(", ...");
405+
for j in PRINT_ELEMENTS_LIMIT + overflow..PRINT_ELEMENTS_LIMIT * 2 + overflow {
406+
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
407+
}
408+
expected_output.push_str(if i == PRINT_ELEMENTS_LIMIT * 2 + overflow - 1 {
409+
"]"
410+
} else {
411+
"],\n "
412+
});
413+
}
414+
expected_output.push(']');
415+
let actual_output = format!("{}", a);
416+
417+
print_output_diff(&expected_output, &actual_output);
418+
assert_eq!(actual_output, expected_output);
419+
}
420+
}

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ pub use crate::zip::{
190190
};
191191

192192
pub use crate::layout::Layout;
193-
pub use crate::arrayformat::PRINT_ELEMENTS_LIMIT;
194193

195194
/// Implementation's prelude. Common types used everywhere.
196195
mod imp_prelude {

tests/format.rs

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate ndarray;
22

33
use ndarray::prelude::*;
4-
use ndarray::{rcarr1, PRINT_ELEMENTS_LIMIT};
4+
use ndarray::rcarr1;
55

66
#[test]
77
fn formatting()
@@ -36,132 +36,6 @@ fn formatting()
3636
assert_eq!(s, "[01, ff, fe]");
3737
}
3838

39-
#[cfg(test)]
40-
mod formatting_with_omit {
41-
use super::*;
42-
43-
fn print_output_diff(expected: &str, actual: &str) {
44-
println!("Expected output:\n{}\nActual output:\n{}", expected, actual);
45-
}
46-
47-
#[test]
48-
fn dim_1() {
49-
let overflow: usize = 5;
50-
let a = Array1::from_elem((PRINT_ELEMENTS_LIMIT * 2 + overflow, ), 1);
51-
let mut expected_output = String::from("[");
52-
a.iter()
53-
.take(PRINT_ELEMENTS_LIMIT)
54-
.for_each(|elem| { expected_output.push_str(format!("{}, ", elem).as_str()) });
55-
expected_output.push_str("...");
56-
a.iter()
57-
.skip(PRINT_ELEMENTS_LIMIT + overflow)
58-
.for_each(|elem| { expected_output.push_str(format!(", {}", elem).as_str()) });
59-
expected_output.push(']');
60-
let actual_output = format!("{}", a);
61-
62-
print_output_diff(&expected_output, &actual_output);
63-
assert_eq!(actual_output, expected_output);
64-
}
65-
66-
#[test]
67-
fn dim_2_last_axis_overflow() {
68-
let overflow: usize = 3;
69-
let a = Array2::from_elem((PRINT_ELEMENTS_LIMIT, PRINT_ELEMENTS_LIMIT * 2 + overflow), 1);
70-
let mut expected_output = String::from("[");
71-
72-
for i in 0..PRINT_ELEMENTS_LIMIT {
73-
expected_output.push_str(format!("[{}", a[(i, 0)]).as_str());
74-
for j in 1..PRINT_ELEMENTS_LIMIT {
75-
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
76-
}
77-
expected_output.push_str(", ...");
78-
for j in PRINT_ELEMENTS_LIMIT + overflow..PRINT_ELEMENTS_LIMIT * 2 + overflow {
79-
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
80-
}
81-
expected_output.push_str(if i < PRINT_ELEMENTS_LIMIT - 1 { "],\n " } else { "]" });
82-
}
83-
expected_output.push(']');
84-
let actual_output = format!("{}", a);
85-
86-
print_output_diff(&expected_output, &actual_output);
87-
assert_eq!(actual_output, expected_output);
88-
}
89-
90-
#[test]
91-
fn dim_2_non_last_axis_overflow() {
92-
let overflow: usize = 5;
93-
let a = Array2::from_elem((PRINT_ELEMENTS_LIMIT * 2 + overflow, PRINT_ELEMENTS_LIMIT), 1);
94-
let mut expected_output = String::from("[");
95-
96-
for i in 0..PRINT_ELEMENTS_LIMIT {
97-
expected_output.push_str(format!("[{}", a[(i, 0)]).as_str());
98-
for j in 1..PRINT_ELEMENTS_LIMIT {
99-
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
100-
}
101-
expected_output.push_str("],\n ");
102-
}
103-
expected_output.push_str("...,\n ");
104-
for i in PRINT_ELEMENTS_LIMIT + overflow..PRINT_ELEMENTS_LIMIT * 2 + overflow {
105-
expected_output.push_str(format!("[{}", a[(i, 0)]).as_str());
106-
for j in 1..PRINT_ELEMENTS_LIMIT {
107-
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
108-
}
109-
expected_output.push_str(if i == PRINT_ELEMENTS_LIMIT * 2 + overflow - 1 {
110-
"]"
111-
} else {
112-
"],\n "
113-
});
114-
}
115-
expected_output.push(']');
116-
let actual_output = format!("{}", a);
117-
118-
print_output_diff(&expected_output, &actual_output);
119-
assert_eq!(actual_output, expected_output);
120-
}
121-
122-
#[test]
123-
fn dim_2_multi_directional_overflow() {
124-
let overflow: usize = 5;
125-
let a = Array2::from_elem(
126-
(PRINT_ELEMENTS_LIMIT * 2 + overflow, PRINT_ELEMENTS_LIMIT * 2 + overflow), 1
127-
);
128-
let mut expected_output = String::from("[");
129-
130-
for i in 0..PRINT_ELEMENTS_LIMIT {
131-
expected_output.push_str(format!("[{}", a[(i, 0)]).as_str());
132-
for j in 1..PRINT_ELEMENTS_LIMIT {
133-
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
134-
}
135-
expected_output.push_str(", ...");
136-
for j in PRINT_ELEMENTS_LIMIT + overflow..PRINT_ELEMENTS_LIMIT * 2 + overflow {
137-
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
138-
}
139-
expected_output.push_str("],\n ");
140-
}
141-
expected_output.push_str("...,\n ");
142-
for i in PRINT_ELEMENTS_LIMIT + overflow..PRINT_ELEMENTS_LIMIT * 2 + overflow {
143-
expected_output.push_str(format!("[{}", a[(i, 0)]).as_str());
144-
for j in 1..PRINT_ELEMENTS_LIMIT {
145-
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
146-
}
147-
expected_output.push_str(", ...");
148-
for j in PRINT_ELEMENTS_LIMIT + overflow..PRINT_ELEMENTS_LIMIT * 2 + overflow {
149-
expected_output.push_str(format!(", {}", a[(i, j)]).as_str());
150-
}
151-
expected_output.push_str(if i == PRINT_ELEMENTS_LIMIT * 2 + overflow - 1 {
152-
"]"
153-
} else {
154-
"],\n "
155-
});
156-
}
157-
expected_output.push(']');
158-
let actual_output = format!("{}", a);
159-
160-
print_output_diff(&expected_output, &actual_output);
161-
assert_eq!(actual_output, expected_output);
162-
}
163-
}
164-
16539
#[test]
16640
fn debug_format() {
16741
let a = Array2::<i32>::zeros((3, 4));

0 commit comments

Comments
 (0)