diff --git a/externalsort/io_test.go b/externalsort/io_test.go index ceb6ed7..129677f 100644 --- a/externalsort/io_test.go +++ b/externalsort/io_test.go @@ -51,8 +51,9 @@ func TestLineReader(t *testing.T) { { name: "linebreak", in: `abc + `, - expected: []string{"abc\n"}, + expected: []string{"abc", ""}, }, { name: "multiple-rows", @@ -61,7 +62,7 @@ func TestLineReader(t *testing.T) { b b `, - expected: []string{"a\n", "\n", "b\n", "b\n"}, + expected: []string{"a", "", "b", "b"}, }, { name: "large-row", @@ -98,7 +99,6 @@ b lines, err := readAll(lineReader) require.NoError(t, err) - require.Equal(t, strings.Join(lines, ""), tc.in) require.Len(t, lines, len(tc.expected), "expected: %+v, got: %+v", tc.expected, lines) require.Equal(t, tc.expected, lines) @@ -108,16 +108,22 @@ b type brokenReader int -func (b brokenReader) Read(data []byte) (n int, err error) { +func (r brokenReader) Read(data []byte) (n int, err error) { return 0, errors.New("read is broken") } +type eofReader int + +func (r eofReader) Read(p []byte) (n int, err error) { + return 0, io.EOF +} + func TestLineReader_error(t *testing.T) { _, err := NewReader(new(brokenReader)).ReadLine() require.Error(t, err) require.False(t, errors.Is(err, io.EOF)) - r := newStringReader("") + r := NewReader(new(eofReader)) _, err = r.ReadLine() require.True(t, errors.Is(err, io.EOF)) } @@ -128,11 +134,12 @@ func TestLineWriter(t *testing.T) { lines []string }{ { - name: "empty", + name: "empty", + lines: []string{""}, }, { name: "simple", - lines: []string{"a\n", "b\n", "c\n"}, + lines: []string{"a", "b", "c"}, }, { name: "large-line", @@ -153,7 +160,8 @@ func TestLineWriter(t *testing.T) { } require.NoError(t, w.Flush()) - require.Equal(t, strings.Join(tc.lines, ""), buf.String()) + expected := strings.Join(tc.lines, "\n") + "\n" + require.Equal(t, expected, buf.String()) }) } } diff --git a/externalsort/sort_test.go b/externalsort/sort_test.go index 63535ad..9499725 100644 --- a/externalsort/sort_test.go +++ b/externalsort/sort_test.go @@ -28,7 +28,8 @@ func TestMerge(t *testing.T) { out: `0 1 1 -1`, +1 +`, }, { // Merge believes lines are read in sorted order. @@ -36,7 +37,8 @@ func TestMerge(t *testing.T) { in: []string{`1 0`}, out: `1 -0`, +0 +`, }, } { t.Run(tc.name, func(t *testing.T) { diff --git a/externalsort/testdata/sort/1/out.txt b/externalsort/testdata/sort/1/out.txt index f2ba8f8..8baef1b 100644 Binary files a/externalsort/testdata/sort/1/out.txt and b/externalsort/testdata/sort/1/out.txt differ diff --git a/externalsort/testdata/sort/3/out.txt b/externalsort/testdata/sort/3/out.txt index b97a368..36fc464 100644 Binary files a/externalsort/testdata/sort/3/out.txt and b/externalsort/testdata/sort/3/out.txt differ diff --git a/externalsort/testdata/sort/6/in2.txt b/externalsort/testdata/sort/6/in2.txt index 74c9df3..99065bb 100644 Binary files a/externalsort/testdata/sort/6/in2.txt and b/externalsort/testdata/sort/6/in2.txt differ diff --git a/externalsort/testdata/sort/6/out.txt b/externalsort/testdata/sort/6/out.txt index b2cf317..00ceb07 100644 Binary files a/externalsort/testdata/sort/6/out.txt and b/externalsort/testdata/sort/6/out.txt differ diff --git a/externalsort/testdata/sort/7/in1.txt b/externalsort/testdata/sort/7/in1.txt new file mode 100644 index 0000000..f29fb95 Binary files /dev/null and b/externalsort/testdata/sort/7/in1.txt differ diff --git a/externalsort/testdata/sort/7/in10.txt b/externalsort/testdata/sort/7/in10.txt new file mode 100644 index 0000000..bc342d6 Binary files /dev/null and b/externalsort/testdata/sort/7/in10.txt differ diff --git a/externalsort/testdata/sort/7/in2.txt b/externalsort/testdata/sort/7/in2.txt new file mode 100644 index 0000000..6f7a4c2 Binary files /dev/null and b/externalsort/testdata/sort/7/in2.txt differ diff --git a/externalsort/testdata/sort/7/in3.txt b/externalsort/testdata/sort/7/in3.txt new file mode 100644 index 0000000..056c1c2 Binary files /dev/null and b/externalsort/testdata/sort/7/in3.txt differ diff --git a/externalsort/testdata/sort/7/in4.txt b/externalsort/testdata/sort/7/in4.txt new file mode 100644 index 0000000..4509a9c Binary files /dev/null and b/externalsort/testdata/sort/7/in4.txt differ diff --git a/externalsort/testdata/sort/7/in5.txt b/externalsort/testdata/sort/7/in5.txt new file mode 100644 index 0000000..d10880f Binary files /dev/null and b/externalsort/testdata/sort/7/in5.txt differ diff --git a/externalsort/testdata/sort/7/in6.txt b/externalsort/testdata/sort/7/in6.txt new file mode 100644 index 0000000..c894bf6 Binary files /dev/null and b/externalsort/testdata/sort/7/in6.txt differ diff --git a/externalsort/testdata/sort/7/in7.txt b/externalsort/testdata/sort/7/in7.txt new file mode 100644 index 0000000..27c37b8 Binary files /dev/null and b/externalsort/testdata/sort/7/in7.txt differ diff --git a/externalsort/testdata/sort/7/in8.txt b/externalsort/testdata/sort/7/in8.txt new file mode 100644 index 0000000..6174927 Binary files /dev/null and b/externalsort/testdata/sort/7/in8.txt differ diff --git a/externalsort/testdata/sort/7/in9.txt b/externalsort/testdata/sort/7/in9.txt new file mode 100644 index 0000000..e69347f Binary files /dev/null and b/externalsort/testdata/sort/7/in9.txt differ diff --git a/externalsort/testdata/sort/7/out.txt b/externalsort/testdata/sort/7/out.txt new file mode 100644 index 0000000..03e6e78 Binary files /dev/null and b/externalsort/testdata/sort/7/out.txt differ