Skip to content
Snippets Groups Projects
Commit a170be5f authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Initial commit.

parents
Branches
Tags
No related merge requests found
*~
*.pyc
*.pyo
.idea
from math import inf
from random import randrange, choice
SUITE_TEMPLATE = '''
from math import inf
from unittest import TestCase
from main import SmallestPositiveApp
class Test(TestCase):
{tests}
'''[1:-1]
TEST_TEMPLATE = '''
def test_parse_{number}(self):
inputs = {inputs}
expected = {expected}
actual = SmallestPositiveApp._find_smallest_positive(inputs)
self.assertEqual(actual, expected)
'''[1:]
VALUE_LIMIT = 100
PADDING_LIMIT = 5
def generate_padding(smallest_positive):
result = []
for _ in range(randrange(PADDING_LIMIT)):
options = [
randrange(-VALUE_LIMIT, 0),
0,
]
if smallest_positive < VALUE_LIMIT:
options.append(randrange(smallest_positive, VALUE_LIMIT + 1))
result.append(choice(options))
return result
def generate_random_test(number):
smallest_positive = choice((randrange(VALUE_LIMIT), inf))
inputs = [smallest_positive] # TODO
return TEST_TEMPLATE.format(number=number, inputs=inputs, expected=smallest_positive)
def main():
print(SUITE_TEMPLATE.format(tests='\n'.join(generate_random_test(number) for number in range(100))), end='')
if __name__ == '__main__':
main()
main.py 0 → 100644
from math import inf
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import NumericProperty, StringProperty
class Field(BoxLayout):
label_text = StringProperty()
class SmallestPositiveApp(App):
smallest_positive = NumericProperty(inf)
def add_field(self):
container = self.root.ids.fields
container.add_widget(Field(label_text=f'Field #{len(container.children)}: '))
def remove_field(self):
container = self.root.ids.fields
if len(container.children) > 0:
container.remove_widget(container.children[0])
@staticmethod
def _find_smallest_positive(values):
smallest_positive = inf
for value in values:
if 0 < value < smallest_positive:
smallest_positive = value
return smallest_positive
def update(self):
container = self.root.ids.fields
values = []
for field in container.children:
try:
values.append(float(field.ids.input.text))
except ValueError:
pass
self.smallest_positive = SmallestPositiveApp._find_smallest_positive(values)
if __name__ == '__main__':
app = SmallestPositiveApp()
app.run()
BoxLayout:
orientation: 'vertical'
BoxLayout:
id: fields
orientation: 'vertical'
size_hint: (1.0, 6.0)
BoxLayout:
orientation: 'horizontal'
Button:
text: 'Add Field'
font_size: sp(24)
on_press: app.add_field()
Button:
text: 'Remove Field'
font_size: sp(24)
on_press: app.remove_field()
Label:
id: result
text: f'Smallest Positive: {app.smallest_positive}'
font_size: sp(24)
<Field>:
orientation: 'horizontal'
Label:
text: root.label_text
font_size: sp(24)
TextInput:
id: input
multiline: False
write_tab: False
font_size: sp(24)
on_text: app.update()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment