Skip to content

Commit 0fa1c61

Browse files
committed
seq:add more tests
Issue #6935
1 parent 6ef9921 commit 0fa1c61

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

tests/by-util/test_seq.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,3 +816,73 @@ fn test_parse_scientific_zero() {
816816
.succeeds()
817817
.stdout_only("0\n1\n");
818818
}
819+
820+
#[test]
821+
fn test_parse_valid_hexadecimal_float() {
822+
new_ucmd!()
823+
.args(&["0x1p-1", "2"])
824+
.succeeds()
825+
.stdout_only("0.5\n1.5\n");
826+
827+
new_ucmd!()
828+
.args(&["1", "0x1p-1", "2"])
829+
.succeeds()
830+
.stdout_only("1.0\n1.5\n2.0\n");
831+
832+
new_ucmd!()
833+
.args(&["0x3.4p-1", "0x4p-1", "4"])
834+
.succeeds()
835+
.stdout_only("1.625\n3.625\n");
836+
837+
new_ucmd!()
838+
.args(&["0x3.4p-1", "0x4p-1", "4"])
839+
.succeeds()
840+
.stdout_only("1.625\n3.625\n");
841+
842+
new_ucmd!()
843+
.args(&[" 0x.8p16", "32768"])
844+
.succeeds()
845+
.stdout_only("32768\n");
846+
}
847+
848+
#[ignore]
849+
#[test]
850+
fn test_parse_valid_hexadecimal_float_format_issues() {
851+
// Parsing is OK, but value representation conflicts with the GNU seq.
852+
853+
// Test output: 4095.953125
854+
// In fact, the 4095.953125 is correct value.
855+
// (65535 + 4/16)*2^(-4) = 4095.953125
856+
// So, it looks like a formatting or output rounding differences
857+
new_ucmd!()
858+
.args(&["0xffff.4p-4", "4096"])
859+
.succeeds()
860+
.stdout_only("4095.95\n");
861+
862+
// Test output: 1023.999999999068677425384521484375
863+
// 0xffffffffff = 1099511627775
864+
// 2^(-30) = 1 / 1073741824
865+
// 1099511627775 / 1073741824 = 1024
866+
new_ucmd!()
867+
.args(&["0xffffffffffp-30", "1024"]) // spell-checker:disable-line
868+
.succeeds()
869+
.stdout_only("1024\n");
870+
871+
// Test output: 5.330078125
872+
new_ucmd!()
873+
.args(&["0xa.a9p-1", "6"])
874+
.succeeds()
875+
.stdout_only("5.33008\n");
876+
877+
// Test output: 5.330078125
878+
new_ucmd!()
879+
.args(&["0xA.A9p-1", "6"])
880+
.succeeds()
881+
.stdout_only("5.33008\n");
882+
883+
//Test output: 0.00000000992804416455328464508056640625
884+
new_ucmd!()
885+
.args(&["0xa.a9p-30", "1"])
886+
.succeeds()
887+
.stdout_only("9.92804e-09\n1\n");
888+
}

0 commit comments

Comments
 (0)