From: Ben Pfaff Date: Tue, 10 Jun 2025 14:46:16 +0000 (-0700) Subject: more test cases X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9be0aebbc2ec11682cc591ea21e5bfa819cc6de;p=pspp more test cases --- diff --git a/rust/pspp/src/sys/raw.rs b/rust/pspp/src/sys/raw.rs index f931d38a50..acd0a47fe2 100644 --- a/rust/pspp/src/sys/raw.rs +++ b/rust/pspp/src/sys/raw.rs @@ -982,7 +982,10 @@ where ztrailer_len, ) { Ok(None) => Some(Ok(Record::Cases(Rc::new(RefCell::new(self.cases()))))), - Ok(Some(ztrailer)) => Some(Ok(Record::ZTrailer(ztrailer))), + Ok(Some(ztrailer)) => { + self.state = ReaderState::Cases; + Some(Ok(Record::ZTrailer(ztrailer))) + } Err(error) => Some(Err(error)), } } diff --git a/rust/pspp/src/sys/test.rs b/rust/pspp/src/sys/test.rs index 267c54b439..4a58599d94 100644 --- a/rust/pspp/src/sys/test.rs +++ b/rust/pspp/src/sys/test.rs @@ -107,6 +107,16 @@ fn compressed_data_other_bias() { test_sysfile("compressed_data_other_bias"); } +#[test] +fn zcompressed_data() { + test_sysfile("zcompressed_data"); +} + +#[test] +fn no_variables() { + test_sysfile("no_variables"); +} + fn test_sysfile(name: &str) { let input_filename = Path::new(env!("CARGO_MANIFEST_DIR")) .join("src/sys/testdata") diff --git a/rust/pspp/src/sys/testdata/compressed_data_other_bias.expected b/rust/pspp/src/sys/testdata/compressed_data_other_bias.expected new file mode 100644 index 0000000000..f57bc54fa1 --- /dev/null +++ b/rust/pspp/src/sys/testdata/compressed_data_other_bias.expected @@ -0,0 +1,25 @@ +Compression bias is 50 instead of the usual values of 0 or 100. + +╭──────────────────────┬────────────────────────╮ +│ Created │ 01-JAN-2011 20:53:52│ +├──────────────────────┼────────────────────────┤ +│Writer Product │PSPP synthetic test file│ +├──────────────────────┼────────────────────────┤ +│ Compression │SAV │ +│ Number of Cases│Unknown │ +╰──────────────────────┴────────────────────────╯ + +╭─────────┬────────────────────────╮ +│Label │PSPP synthetic test file│ +│Variables│ 5│ +╰─────────┴────────────────────────╯ + +╭─────┬────────┬─────┬─────────────────┬─────┬─────┬─────────┬────────────┬────────────┬──────────────╮ +│ │Position│Label│Measurement Level│ Role│Width│Alignment│Print Format│Write Format│Missing Values│ +├─────┼────────┼─────┼─────────────────┼─────┼─────┼─────────┼────────────┼────────────┼──────────────┤ +│num1 │ 1│ │ │Input│ 8│Right │F8.0 │F8.0 │ │ +│num2 │ 2│ │ │Input│ 8│Right │F8.0 │F8.0 │ │ +│str4 │ 3│ │Nominal │Input│ 4│Left │A4 │A4 │ │ +│str8 │ 4│ │Nominal │Input│ 8│Left │A8 │A8 │ │ +│str15│ 5│ │Nominal │Input│ 15│Left │A15 │A15 │ │ +╰─────┴────────┴─────┴─────────────────┴─────┴─────┴─────────┴────────────┴────────────┴──────────────╯ diff --git a/rust/pspp/src/sys/testdata/compressed_data_other_bias.sack b/rust/pspp/src/sys/testdata/compressed_data_other_bias.sack new file mode 100644 index 0000000000..3db9812d11 --- /dev/null +++ b/rust/pspp/src/sys/testdata/compressed_data_other_bias.sack @@ -0,0 +1,32 @@ +# File header. +"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file"; +2; # Layout code +6; # Nominal case size +1; # Simple compression. +0; # Not weighted +-1; # Unspecified number of cases. +50.0; # Bias. +"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file"; +i8 0 *3; + +# Numeric variables. +2; 0; 0; 0; 0x050800 *2; s8 "NUM1"; +2; 0; 0; 0; 0x050800 *2; s8 "NUM2"; + +# String variable. +2; 4; 0; 0; 0x010400 *2; s8 "STR4"; +2; 8; 0; 0; 0x010800 *2; s8 "STR8"; +2; 15; 0; 0; 0x010f00 *2; s8 "STR15"; +2; -1; 0; 0; 0; 0; s8 ""; + +# Character encoding record. +7; 20; 1; 12; "windows-1252"; + +# Dictionary termination record. +999; 0; + +# Compressed data. +i8 1 100 254 253 254 253; i8 255 251; "abcdefgh"; s8 "0123"; +i8 253 253 253 254; i8 101 102 253 253; s8 "jklm"; s8 "nopqrstu"; +s8 "vwxyzABC"; s8 "DEFG"; s8 "HIJKLMNO"; +i8 254 253 252 0 0 0 0 0; s8 "PQRSTUVW"; diff --git a/rust/pspp/src/sys/testdata/compressed_data_zero_bias.expected b/rust/pspp/src/sys/testdata/compressed_data_zero_bias.expected new file mode 100644 index 0000000000..f36fb5ebce --- /dev/null +++ b/rust/pspp/src/sys/testdata/compressed_data_zero_bias.expected @@ -0,0 +1,23 @@ +╭──────────────────────┬────────────────────────╮ +│ Created │ 01-JAN-2011 20:53:52│ +├──────────────────────┼────────────────────────┤ +│Writer Product │PSPP synthetic test file│ +├──────────────────────┼────────────────────────┤ +│ Compression │SAV │ +│ Number of Cases│Unknown │ +╰──────────────────────┴────────────────────────╯ + +╭─────────┬────────────────────────╮ +│Label │PSPP synthetic test file│ +│Variables│ 5│ +╰─────────┴────────────────────────╯ + +╭─────┬────────┬─────┬─────────────────┬─────┬─────┬─────────┬────────────┬────────────┬──────────────╮ +│ │Position│Label│Measurement Level│ Role│Width│Alignment│Print Format│Write Format│Missing Values│ +├─────┼────────┼─────┼─────────────────┼─────┼─────┼─────────┼────────────┼────────────┼──────────────┤ +│num1 │ 1│ │ │Input│ 8│Right │F8.0 │F8.0 │ │ +│num2 │ 2│ │ │Input│ 8│Right │F8.0 │F8.0 │ │ +│str4 │ 3│ │Nominal │Input│ 4│Left │A4 │A4 │ │ +│str8 │ 4│ │Nominal │Input│ 8│Left │A8 │A8 │ │ +│str15│ 5│ │Nominal │Input│ 15│Left │A15 │A15 │ │ +╰─────┴────────┴─────┴─────────────────┴─────┴─────┴─────────┴────────────┴────────────┴──────────────╯ diff --git a/rust/pspp/src/sys/testdata/compressed_data_zero_bias.sack b/rust/pspp/src/sys/testdata/compressed_data_zero_bias.sack new file mode 100644 index 0000000000..7d892e9014 --- /dev/null +++ b/rust/pspp/src/sys/testdata/compressed_data_zero_bias.sack @@ -0,0 +1,32 @@ +# File header. +"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file"; +2; # Layout code +6; # Nominal case size +1; # Simple compression. +0; # Not weighted +-1; # Unspecified number of cases. +0.0; # Bias. +"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file"; +i8 0 *3; + +# Numeric variables. +2; 0; 0; 0; 0x050800 *2; s8 "NUM1"; +2; 0; 0; 0; 0x050800 *2; s8 "NUM2"; + +# String variable. +2; 4; 0; 0; 0x010400 *2; s8 "STR4"; +2; 8; 0; 0; 0x010800 *2; s8 "STR8"; +2; 15; 0; 0; 0x010f00 *2; s8 "STR15"; +2; -1; 0; 0; 0; 0; s8 ""; + +# Character encoding record. +7; 20; 1; 12; "windows-1252"; + +# Dictionary termination record. +999; 0; + +# Compressed data. +i8 1 100 254 253 254 253; i8 255 251; "abcdefgh"; s8 "0123"; +i8 253 253 253 254; i8 101 102 253 253; s8 "jklm"; s8 "nopqrstu"; +s8 "vwxyzABC"; s8 "DEFG"; s8 "HIJKLMNO"; +i8 254 253 252 0 0 0 0 0; s8 "PQRSTUVW"; diff --git a/rust/pspp/src/sys/testdata/no_variables.expected b/rust/pspp/src/sys/testdata/no_variables.expected new file mode 100644 index 0000000000..b10e8d94b3 --- /dev/null +++ b/rust/pspp/src/sys/testdata/no_variables.expected @@ -0,0 +1,14 @@ +╭──────────────────────┬────────────────────────╮ +│ Created │ 01-JAN-2011 20:53:52│ +├──────────────────────┼────────────────────────┤ +│Writer Product │PSPP synthetic test file│ +├──────────────────────┼────────────────────────┤ +│ Compression │None │ +│ Number of Cases│ 0│ +╰──────────────────────┴────────────────────────╯ + +╭─────────┬────────────────────────╮ +│Label │PSPP synthetic test file│ +│Variables│ 0│ +╰─────────┴────────────────────────╯ + diff --git a/rust/pspp/src/sys/testdata/no_variables.sack b/rust/pspp/src/sys/testdata/no_variables.sack new file mode 100644 index 0000000000..afe6f05731 --- /dev/null +++ b/rust/pspp/src/sys/testdata/no_variables.sack @@ -0,0 +1,16 @@ +# File header. +"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file"; +2; # Layout code +0; # Nominal case size (empty) +0; # Not compressed +0; # Not weighted +0; # 0 cases. +100.0; # Bias. +"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file"; +i8 0 *3; + +# Character encoding record. +7; 20; 1; 12; "windows-1252"; + +# Dictionary termination record. +999; 0; diff --git a/rust/pspp/src/sys/testdata/zcompressed_data.expected b/rust/pspp/src/sys/testdata/zcompressed_data.expected new file mode 100644 index 0000000000..396ece9038 --- /dev/null +++ b/rust/pspp/src/sys/testdata/zcompressed_data.expected @@ -0,0 +1,23 @@ +╭──────────────────────┬────────────────────────╮ +│ Created │ 01-JAN-2011 20:53:52│ +├──────────────────────┼────────────────────────┤ +│Writer Product │PSPP synthetic test file│ +├──────────────────────┼────────────────────────┤ +│ Compression │ZSAV │ +│ Number of Cases│Unknown │ +╰──────────────────────┴────────────────────────╯ + +╭─────────┬────────────────────────╮ +│Label │PSPP synthetic test file│ +│Variables│ 5│ +╰─────────┴────────────────────────╯ + +╭─────┬────────┬─────┬─────────────────┬─────┬─────┬─────────┬────────────┬────────────┬──────────────╮ +│ │Position│Label│Measurement Level│ Role│Width│Alignment│Print Format│Write Format│Missing Values│ +├─────┼────────┼─────┼─────────────────┼─────┼─────┼─────────┼────────────┼────────────┼──────────────┤ +│num1 │ 1│ │ │Input│ 8│Right │F8.0 │F8.0 │ │ +│num2 │ 2│ │ │Input│ 8│Right │F8.0 │F8.0 │ │ +│str4 │ 3│ │Nominal │Input│ 4│Left │A4 │A4 │ │ +│str8 │ 4│ │Nominal │Input│ 8│Left │A8 │A8 │ │ +│str15│ 5│ │Nominal │Input│ 15│Left │A15 │A15 │ │ +╰─────┴────────┴─────┴─────────────────┴─────┴─────┴─────────┴────────────┴────────────┴──────────────╯ diff --git a/rust/pspp/src/sys/testdata/zcompressed_data.sack b/rust/pspp/src/sys/testdata/zcompressed_data.sack new file mode 100644 index 0000000000..4065f89303 --- /dev/null +++ b/rust/pspp/src/sys/testdata/zcompressed_data.sack @@ -0,0 +1,62 @@ +# File header. +"$FL3"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file"; +2; # Layout code +6; # Nominal case size +2; # zlib compressed +0; # Not weighted +-1; # Unspecified number of cases. +100.0; # Bias. +"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file"; +i8 0 *3; + +# Numeric variables. +2; 0; 0; 0; 0x050800 *2; s8 "NUM1"; +2; 0; 0; 0; 0x050800 *2; s8 "NUM2"; + +# String variable. +2; 4; 0; 0; 0x010400 *2; s8 "STR4"; +2; 8; 0; 0; 0x010800 *2; s8 "STR8"; +2; 15; 0; 0; 0x010f00 *2; s8 "STR15"; +2; -1; 0; 0; 0; 0; s8 ""; + +# Character encoding record. +7; 20; 1; 12; "windows-1252"; + +# Dictionary termination record. +999; 0; + +# ZLIB data header. +i64 0x194; # zheader_ofs +i64 0x205; # ztrailer_ofs +i64 48; # ztrailer_len + +# ZLIB data block. +# +# This is the compressed form of: +# +# 01 64 fe fd fe fd ff fb 61 62 63 64 65 66 67 68 |.d......abcdefgh| +# 30 31 32 33 20 20 20 20 fd fd fd fe 65 66 fd fd |0123 ....ef..| +# 6a 6b 6c 6d 20 20 20 20 6e 6f 70 71 72 73 74 75 |jklm nopqrstu| +# 76 77 78 79 7a 41 42 43 44 45 46 47 20 20 20 20 |vwxyzABCDEFG | +# 48 49 4a 4b 4c 4d 4e 4f fe fd fc 00 00 00 00 00 |HIJKLMNO........| +# 50 51 52 53 54 55 56 57 |PQRSTUVW| +# +# which is the data from the "compressed data" test. +hex "78 01 63 4c f9 f7 f7 df df ff bf 13 93 92 53 52"; +hex "d3 d2 33 0c 0c 8d 8c 15 80 e0 ef df bf ff 52 d3"; +hex "fe fe cd ca ce c9 05 f1 f3 f2 0b 0a 8b 8a 4b 4a"; +hex "cb ca 2b 2a ab 1c 9d 9c 5d 5c dd dc 41 e2 1e 9e"; +hex "5e de 3e be 7e fe ff fe fe 61 00 81 80 c0 a0 e0"; +hex "90 d0 b0 70 00 0f 3f 23 d7"; + +# ZLIB data trailer fixed header: +i64 -100; # ztrailer_bias +i64 0; # ztrailer_zero +0x3ff000; # block_size +1; # n_blocks + +# ZLIB block descriptor: +i64 0x194; # uncompressed_ofs +i64 0x1ac; # compressed_ofs +88; # uncompressed_size +89; # compressed_size