Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test not passing #1

Closed
ww9 opened this issue Mar 1, 2019 · 9 comments
Closed

Test not passing #1

ww9 opened this issue Mar 1, 2019 · 9 comments

Comments

@ww9
Copy link

ww9 commented Mar 1, 2019

Hi, not sure if I'm doing something wrong but the test isn't passing for me :(

$ go test
--- FAIL: TestMultiType (0.00s)
    intersort_test.go:131: sorted map should contain "<nil> 0xc00005c940 0xc00005c948"
    intersort_test.go:131: sorted map should contain "1 2 3"
    intersort_test.go:131: sorted map should contain "a b c"
    intersort_test.go:131: sorted map should contain "false true"
    intersort_test.go:131: sorted map should contain "{0 1} {1 0}"
    intersort_test.go:131: sorted map should contain "[0 1] [1 0]"
FAIL
exit status 1
FAIL    github.com/ww9/intersort        0.334s

$ go version
go version go1.12 windows/amd64
@lukechampine
Copy link
Owner

There's a bug in Go 1.12 that prevents it from sorting these multi-type slices properly. See golang/go#30398

If you use the internal/fmtsort package from tip it should pass.

@ww9
Copy link
Author

ww9 commented Mar 1, 2019

I'll wait for the next release.
Thanks for the quick response!

@ww9 ww9 closed this as completed Mar 1, 2019
@lukechampine
Copy link
Owner

You can get it working by changing a single line in the stdlib. Open $GOROOT/src/internal/fmtsort/sort.go and apply this patch:

@@ -167,7 +167,7 @@ func compare(aVal, bVal reflect.Value) int {
		if c, ok := nilCompare(aVal, bVal); ok {
			return c
		}
-		c := compare(reflect.ValueOf(aType), reflect.ValueOf(bType))
+		c := compare(reflect.ValueOf(aVal.Elem().Type()), reflect.ValueOf(bVal.Elem().Type()))
		if c != 0 {
			return c
		}

The test should then pass.

@ww9
Copy link
Author

ww9 commented Mar 1, 2019

Indeed it fixed! And I learned something amazing in the process:

Go standard library code is recompiled every time if need be. It's not just a large binary .so or .dll file that you need to manually recompile after every change. So just altering that one line you told me and issuing another go test worked! Somehow Go scanned its entire stdlib source-code for changes, compiled everything including intersort and run the code all within 335 milliseconds on my old machine.

$ go test
PASS
ok      github.com/ww9/intersort        0.335s

This is amazing, it feels like I'm coding an interpreted language, not a compiled one!

image

Thank you for your attention!

@ww9
Copy link
Author

ww9 commented Mar 1, 2019

I knew that Go compilation was fast and I know there's a lot of caching in the process that makes this faster, including filesystem level cache provided by SO. But still, this gives me pascal/TCC speed tier vibes.

@ww9
Copy link
Author

ww9 commented Mar 1, 2019

My zealotry notwithstanding, I'll take the liberty to re-open this issue so it can help others trying to play with this meme sort. At least until next release of Go supports it. I'll take no offense (and why would I) if you chose to close it. Thanks

@ww9 ww9 reopened this Mar 1, 2019
@lukechampine
Copy link
Owner

Indeed, Go is pretty amazing! :)

I agree, let's leave this open until the fix makes it into a release.

@lukechampine
Copy link
Owner

Go 1.12.1 was released today, including my fix. So tests should now pass if you are running the latest Go release. :) I will mention this in the README.

@ww9
Copy link
Author

ww9 commented Mar 15, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants