Skip to content

Commit

Permalink
Use .column in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
judahrand committed Sep 22, 2023
1 parent 7c199eb commit aa5ce52
Showing 1 changed file with 141 additions and 0 deletions.
141 changes: 141 additions & 0 deletions arrow-row/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,18 @@ mod tests {
let rows = converter.convert_columns(&cols).unwrap();

assert_eq!(rows.offsets, &[0, 8, 16, 24, 32, 40, 48, 56]);
assert_eq!(
rows.column_offsets,
&[
[0, 3, 8],
[0, 3, 8],
[0, 3, 8],
[0, 3, 8],
[0, 3, 8],
[0, 3, 8],
[0, 3, 8],
]
);
assert_eq!(
rows.buffer,
&[
Expand All @@ -1442,6 +1454,18 @@ mod tests {
assert!(rows.row(4) < rows.row(1));
assert!(rows.row(5) < rows.row(4));

assert!(rows.row(3).column(0) < rows.row(6).column(0));
assert!(rows.row(0).column(0) < rows.row(1).column(0));
assert!(rows.row(3).column(0) < rows.row(0).column(0));
assert!(rows.row(4).column(0) == rows.row(1).column(0));
assert!(rows.row(5).column(0) == rows.row(4).column(0));

assert!(rows.row(3).column(1) > rows.row(6).column(1));
assert!(rows.row(0).column(1) < rows.row(1).column(1));
assert!(rows.row(3).column(1) > rows.row(0).column(1));
assert!(rows.row(4).column(1) < rows.row(1).column(1));
assert!(rows.row(5).column(1) < rows.row(4).column(1));

let back = converter.convert_rows(&rows).unwrap();
for (expected, actual) in cols.iter().zip(&back) {
assert_eq!(expected, actual);
Expand Down Expand Up @@ -1471,6 +1495,7 @@ mod tests {
let rows = converter.convert_columns(&[Arc::clone(&col)]).unwrap();
for i in 0..rows.num_rows() - 1 {
assert!(rows.row(i) < rows.row(i + 1));
assert!(rows.row(i).column(0) < rows.row(i + 1).column(0));
}

let back = converter.convert_rows(&rows).unwrap();
Expand Down Expand Up @@ -1503,6 +1528,7 @@ mod tests {
let rows = converter.convert_columns(&[Arc::clone(&col)]).unwrap();
for i in 0..rows.num_rows() - 1 {
assert!(rows.row(i) < rows.row(i + 1));
assert!(rows.row(i).column(0) < rows.row(i + 1).column(0));
}

let back = converter.convert_rows(&rows).unwrap();
Expand All @@ -1523,6 +1549,10 @@ mod tests {
assert!(rows.row(2) > rows.row(0));
assert!(rows.row(1) > rows.row(0));

assert!(rows.row(2).column(0) > rows.row(1).column(0));
assert!(rows.row(2).column(0) > rows.row(0).column(0));
assert!(rows.row(1).column(0) > rows.row(0).column(0));

let cols = converter.convert_rows(&rows).unwrap();
assert_eq!(&cols[0], &col);

Expand All @@ -1539,6 +1569,9 @@ mod tests {
assert!(rows.row(2) < rows.row(1));
assert!(rows.row(2) < rows.row(0));
assert!(rows.row(1) < rows.row(0));
assert!(rows.row(2).column(0) < rows.row(1).column(0));
assert!(rows.row(2).column(0) < rows.row(0).column(0));
assert!(rows.row(1).column(0) < rows.row(0).column(0));
let cols = converter.convert_rows(&rows).unwrap();
assert_eq!(&cols[0], &col);
}
Expand Down Expand Up @@ -1587,6 +1620,7 @@ mod tests {
let rows = converter.convert_columns(&[col]).unwrap();
assert_eq!(rows.num_rows(), 10);
assert_eq!(rows.row(1).data.len(), 0);
assert_eq!(rows.row(1).column(0).len(), 0);
}

#[test]
Expand All @@ -1607,6 +1641,11 @@ mod tests {
assert!(rows.row(3) < rows.row(0));
assert!(rows.row(3) < rows.row(1));

assert!(rows.row(1).column(0) < rows.row(0).column(0));
assert!(rows.row(2).column(0) < rows.row(4).column(0));
assert!(rows.row(3).column(0) < rows.row(0).column(0));
assert!(rows.row(3).column(0) < rows.row(1).column(0));

let cols = converter.convert_rows(&rows).unwrap();
assert_eq!(&cols[0], &col);

Expand Down Expand Up @@ -1644,6 +1683,14 @@ mod tests {
rows.row(i),
rows.row(j)
);
assert!(
rows.row(i).column(0) < rows.row(j).column(0),
"{} < {} - {:?} < {:?}",
i,
j,
rows.row(i).column(0),
rows.row(j).column(0)
);
}
}

Expand All @@ -1670,6 +1717,14 @@ mod tests {
rows.row(i),
rows.row(j)
);
assert!(
rows.row(i).column(0) > rows.row(j).column(0),
"{} < {} - {:?} < {:?}",
i,
j,
rows.row(i).column(0),
rows.row(j).column(0)
);
}
}

Expand Down Expand Up @@ -1715,6 +1770,15 @@ mod tests {
assert_eq!(rows_a.row(1), rows_a.row(6));
assert_eq!(rows_a.row(1), rows_a.row(7));

assert!(rows_a.row(3).column(0) < rows_a.row(5).column(0));
assert!(rows_a.row(2).column(0) < rows_a.row(1).column(0));
assert!(rows_a.row(0).column(0) < rows_a.row(1).column(0));
assert!(rows_a.row(3).column(0) < rows_a.row(0).column(0));

assert_eq!(rows_a.row(1).column(0), rows_a.row(4).column(0));
assert_eq!(rows_a.row(1).column(0), rows_a.row(6).column(0));
assert_eq!(rows_a.row(1).column(0), rows_a.row(7).column(0));

let cols = converter.convert_rows(&rows_a).unwrap();
dictionary_eq(&cols[0], &a);

Expand All @@ -1729,6 +1793,10 @@ mod tests {
assert_eq!(rows_a.row(3), rows_b.row(1));
assert!(rows_b.row(2) < rows_a.row(0));

assert_eq!(rows_a.row(1).column(0), rows_b.row(0).column(0));
assert_eq!(rows_a.row(3).column(0), rows_b.row(1).column(0));
assert!(rows_b.row(2).column(0) < rows_a.row(0).column(0));

let cols = converter.convert_rows(&rows_b).unwrap();
dictionary_eq(&cols[0], &b);

Expand All @@ -1747,6 +1815,11 @@ mod tests {
assert!(rows_c.row(0) > rows_c.row(1));
assert!(rows_c.row(3) > rows_c.row(0));

assert!(rows_c.row(3).column(0) > rows_c.row(5).column(0));
assert!(rows_c.row(2).column(0) > rows_c.row(1).column(0));
assert!(rows_c.row(0).column(0) > rows_c.row(1).column(0));
assert!(rows_c.row(3).column(0) > rows_c.row(0).column(0));

let cols = converter.convert_rows(&rows_c).unwrap();
dictionary_eq(&cols[0], &a);

Expand All @@ -1765,6 +1838,11 @@ mod tests {
assert!(rows_c.row(0) > rows_c.row(1));
assert!(rows_c.row(3) < rows_c.row(0));

assert!(rows_c.row(3).column(0) < rows_c.row(5).column(0));
assert!(rows_c.row(2).column(0) > rows_c.row(1).column(0));
assert!(rows_c.row(0).column(0) > rows_c.row(1).column(0));
assert!(rows_c.row(3).column(0) < rows_c.row(0).column(0));

let cols = converter.convert_rows(&rows_c).unwrap();
dictionary_eq(&cols[0], &a);
}
Expand All @@ -1784,6 +1862,7 @@ mod tests {

for (a, b) in r1.iter().zip(r1.iter().skip(1)) {
assert!(a < b);
assert!(a.column(0) < b.column(0));
}

let back = converter.convert_rows(&r1).unwrap();
Expand All @@ -1806,6 +1885,11 @@ mod tests {
assert_ne!(r1.row(0), r2.row(0)); // Value does not equal null
assert_eq!(r1.row(1), r2.row(1)); // Values equal

assert_eq!(r2.row(0).column(0), r2.row(2).column(0)); // Nulls equal
assert!(r2.row(0).column(0) < r2.row(1).column(0)); // Nulls first
assert_ne!(r1.row(0).column(0), r2.row(0).column(0)); // Value does not equal null
assert_eq!(r1.row(1).column(0), r2.row(1).column(0)); // Values equal

let back = converter.convert_rows(&r2).unwrap();
assert_eq!(back.len(), 1);
assert_eq!(&back[0], &s2);
Expand Down Expand Up @@ -1836,6 +1920,12 @@ mod tests {
assert!(rows.row(3) < rows.row(2));
assert!(rows.row(6) < rows.row(2));
assert!(rows.row(3) < rows.row(6));

assert!(rows.row(0).column(0) < rows.row(1).column(0));
assert!(rows.row(2).column(0) < rows.row(0).column(0));
assert!(rows.row(3).column(0) < rows.row(2).column(0));
assert!(rows.row(6).column(0) < rows.row(2).column(0));
assert!(rows.row(3).column(0) < rows.row(6).column(0));
}

#[test]
Expand Down Expand Up @@ -1864,6 +1954,11 @@ mod tests {
assert_eq!(rows.row(3), rows.row(4));
assert_eq!(rows.row(4), rows.row(5));
assert!(rows.row(3) < rows.row(0));

assert_eq!(rows.row(0).column(0), rows.row(1).column(0));
assert_eq!(rows.row(3).column(0), rows.row(4).column(0));
assert_eq!(rows.row(4).column(0), rows.row(5).column(0));
assert!(rows.row(3).column(0) < rows.row(0).column(0));
}

#[test]
Expand Down Expand Up @@ -1927,6 +2022,13 @@ mod tests {
assert!(rows.row(5) < rows.row(2)); // [] < [32, 42]
assert!(rows.row(3) < rows.row(5)); // null < []

assert!(rows.row(0).column(0) > rows.row(1).column(0)); // [32, 52, 32] > [32, 52, 12]
assert!(rows.row(2).column(0) < rows.row(1).column(0)); // [32, 42] < [32, 52, 12]
assert!(rows.row(3).column(0) < rows.row(2).column(0)); // null < [32, 42]
assert!(rows.row(4).column(0) < rows.row(2).column(0)); // [32, null] < [32, 42]
assert!(rows.row(5).column(0) < rows.row(2).column(0)); // [] < [32, 42]
assert!(rows.row(3).column(0) < rows.row(5).column(0)); // null < []

let back = converter.convert_rows(&rows).unwrap();
assert_eq!(back.len(), 1);
back[0].to_data().validate_full().unwrap();
Expand All @@ -1947,6 +2049,13 @@ mod tests {
assert!(rows.row(5) < rows.row(2)); // [] < [32, 42]
assert!(rows.row(3) > rows.row(5)); // null > []

assert!(rows.row(0).column(0) > rows.row(1).column(0)); // [32, 52, 32] > [32, 52, 12]
assert!(rows.row(2).column(0) < rows.row(1).column(0)); // [32, 42] < [32, 52, 12]
assert!(rows.row(3).column(0) > rows.row(2).column(0)); // null > [32, 42]
assert!(rows.row(4).column(0) > rows.row(2).column(0)); // [32, null] > [32, 42]
assert!(rows.row(5).column(0) < rows.row(2).column(0)); // [] < [32, 42]
assert!(rows.row(3).column(0) > rows.row(5).column(0)); // null > []

let back = converter.convert_rows(&rows).unwrap();
assert_eq!(back.len(), 1);
back[0].to_data().validate_full().unwrap();
Expand All @@ -1967,6 +2076,13 @@ mod tests {
assert!(rows.row(5) > rows.row(2)); // [] > [32, 42]
assert!(rows.row(3) > rows.row(5)); // null > []

assert!(rows.row(0).column(0) < rows.row(1).column(0)); // [32, 52, 32] < [32, 52, 12]
assert!(rows.row(2).column(0) > rows.row(1).column(0)); // [32, 42] > [32, 52, 12]
assert!(rows.row(3).column(0) > rows.row(2).column(0)); // null > [32, 42]
assert!(rows.row(4).column(0) > rows.row(2).column(0)); // [32, null] > [32, 42]
assert!(rows.row(5).column(0) > rows.row(2).column(0)); // [] > [32, 42]
assert!(rows.row(3).column(0) > rows.row(5).column(0)); // null > []

let back = converter.convert_rows(&rows).unwrap();
assert_eq!(back.len(), 1);
back[0].to_data().validate_full().unwrap();
Expand All @@ -1987,6 +2103,13 @@ mod tests {
assert!(rows.row(5) > rows.row(2)); // [] > [32, 42]
assert!(rows.row(3) < rows.row(5)); // null < []

assert!(rows.row(0).column(0) < rows.row(1).column(0)); // [32, 52, 32] < [32, 52, 12]
assert!(rows.row(2).column(0) > rows.row(1).column(0)); // [32, 42] > [32, 52, 12]
assert!(rows.row(3).column(0) < rows.row(2).column(0)); // null < [32, 42]
assert!(rows.row(4).column(0) < rows.row(2).column(0)); // [32, null] < [32, 42]
assert!(rows.row(5).column(0) > rows.row(2).column(0)); // [] > [32, 42]
assert!(rows.row(3).column(0) < rows.row(5).column(0)); // null < []

let back = converter.convert_rows(&rows).unwrap();
assert_eq!(back.len(), 1);
back[0].to_data().validate_full().unwrap();
Expand Down Expand Up @@ -2050,6 +2173,12 @@ mod tests {
assert!(rows.row(4) < rows.row(0));
assert!(rows.row(4) > rows.row(1));

assert!(rows.row(0).column(0) > rows.row(1).column(0));
assert!(rows.row(1).column(0) > rows.row(2).column(0));
assert!(rows.row(2).column(0) > rows.row(3).column(0));
assert!(rows.row(4).column(0) < rows.row(0).column(0));
assert!(rows.row(4).column(0) > rows.row(1).column(0));

let back = converter.convert_rows(&rows).unwrap();
assert_eq!(back.len(), 1);
back[0].to_data().validate_full().unwrap();
Expand All @@ -2069,6 +2198,12 @@ mod tests {
assert!(rows.row(4) > rows.row(0));
assert!(rows.row(4) > rows.row(1));

assert!(rows.row(0).column(0) > rows.row(1).column(0));
assert!(rows.row(1).column(0) > rows.row(2).column(0));
assert!(rows.row(2).column(0) > rows.row(3).column(0));
assert!(rows.row(4).column(0) > rows.row(0).column(0));
assert!(rows.row(4).column(0) > rows.row(1).column(0));

let back = converter.convert_rows(&rows).unwrap();
assert_eq!(back.len(), 1);
back[0].to_data().validate_full().unwrap();
Expand All @@ -2088,6 +2223,12 @@ mod tests {
assert!(rows.row(4) > rows.row(0));
assert!(rows.row(4) < rows.row(1));

assert!(rows.row(0).column(0) < rows.row(1).column(0));
assert!(rows.row(1).column(0) < rows.row(2).column(0));
assert!(rows.row(2).column(0) < rows.row(3).column(0));
assert!(rows.row(4).column(0) > rows.row(0).column(0));
assert!(rows.row(4).column(0) < rows.row(1).column(0));

let back = converter.convert_rows(&rows).unwrap();
assert_eq!(back.len(), 1);
back[0].to_data().validate_full().unwrap();
Expand Down

0 comments on commit aa5ce52

Please sign in to comment.