isaacg1 / pyth

Pyth, an extremely concise language. Try it here:
https://pyth.herokuapp.com/
MIT License
263 stars 57 forks source link

Added test suite feature to interpreter #139

Closed Maltysen closed 9 years ago

Maltysen commented 9 years ago

Adding scaffolding to existing code to make test suites is annoying, messes up byte counts, and does not work with multi-line inputs. So I added that to the online interpreter.

Above the normal input textbox, there is a gray link which says "Test Suite ->":

image

Then when you click on that, it changes the textbox to another one and adds numeric input for input size:

image

When you run it, it runs all of them, and then returns their outputs, separated by linebreaks. The debug parameter is only honored on the first test, the rest all have no debug:

image

The permalinks all also work pretty naturally. Both textboxes are preserved over permalinks, though obviously, it also preserves which one was the current one.

Internally, I have encapsulated the code running in a function, and made two separate handlers for regular submissions and test suites.

I have hosted a live copy on my Koding VM here: http://maltysen.koding.io/ to play around on for bugs & suggestions before deciding on the pull request. I have not done animations for the boxes, but if you think its necessary, I can add it.

jakobkogler commented 9 years ago

Cool feature. However I don't like it, that the tests have a fixed line count. Sometimes the line count varies. Maybe the tests should simply be separated by a line like ====================.

jakobkogler commented 9 years ago

And there's a bug. Try this link. It shows 'Regular Input', but runs the test-suite.

Maltysen commented 9 years ago

@jakobkogler ah no that's the intended behavior, but maybe its not clear. That link is supposed to indicate the other textbox, kind of like pause/play. Maybe I should use an actual chevron glyph instead of ->

jakobkogler commented 9 years ago

Ah, I see.

Why not name it Switch to ...

Maltysen commented 9 years ago

Good idea, updated. I don't really think variable length inputs are common enough to be worth the extra trouble for the constant length ones. I guess we'll wait for issacg1 to decide.

isaacg1 commented 9 years ago

I like the switch to change. I can't actually try it out, because the VM is asleep. Also, I don't think variable length inputs are all that common, and needing to include =================== is rather unintuitive. I like it how it is. I'll merge once I can check it out on the Koding VM. @Maltysen

isaacg1 commented 9 years ago

The code has a bug in submit_test_suite(): If input_size is larger than the number of lines in the input, inputs is an empty list, and inputs[0] throws an error. This leads to the website hanging, as you can see in this test case.

I don't really care about the output in this, such as an error message, no output, or whatever, but the website shouldn't hang. @Maltysen

Maltysen commented 9 years ago

@isaacg1 it just returns an empty string now, by doing if inputs else "".

isaacg1 commented 9 years ago

Excellent. All right, that was the only bug I found, so I'm going to merge.