Skip to content

Instantly share code, notes, and snippets.

@hamiltont
Created October 21, 2014 22:30
Show Gist options
  • Save hamiltont/ebc84568e78ff2272b38 to your computer and use it in GitHub Desktop.
Save hamiltont/ebc84568e78ff2272b38 to your computer and use it in GitHub Desktop.
----------------------- # tests run ------------------------------------
tests = ["1", "1,", "0.23", # Single numbers
"1,5,7", "1,2,-3", "1,1000,12,1,1,1,1,1", # Lists
"1:2:10", "1:2", "10:-2:0", # Sequences
"1,2:1:5" # Complex
]
----------------------- # results! ------------------------------------
Testing 1
Namespace(foo=[1])
Success
Testing 1,
Exception! invalid literal for int() with base 10: ''
Testing 0.23
Exception! invalid literal for int() with base 10: '0.23'
Testing 1,5,7
Namespace(foo=[1, 5, 7])
Success
Testing 1,2,-3
Namespace(foo=[1, 2, 3])
Success
Testing 1,1000,12,1,1,1,1,1
Namespace(foo=[1, 1000, 12, 1, 1, 1, 1, 1])
Success
Testing 1:2:10
Namespace(foo=[1, 3, 5, 7, 9])
Success
Testing 1:2
Invalid: 1:2
Requires start:step:end, e.g. 1:2:10
Exception! need more than 2 values to unpack
Testing 10:-2:0
Namespace(foo=[10, 8, 6, 4, 2])
Success
Testing 1,2:1:5
Namespace(foo=[1, 2, 3, 4])
Success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment