Skip to content

Instantly share code, notes, and snippets.

@Dog
Last active May 21, 2016 16:18
Show Gist options
  • Save Dog/a257729d6c2e99b6685a to your computer and use it in GitHub Desktop.
Save Dog/a257729d6c2e99b6685a to your computer and use it in GitHub Desktop.
Proof Of Concept Problem
import unittest
from slurm import SlurmMachine
"""
From: Zap Brannigan (<zaptheboring@hotmail.com>)
To: Bitshifting Bandit (<bandit@exercism.io>)
My dearest volunteers, conscripts, and death row prisoners-
I write to you today because the DOOP needs your help. Your DOOP needs your
help. More importantly, my DOOP needs your help. Most importantly, I need
you help.
As we all know, Slurm has been the official beverage of planetary invasion
since 2891. However, in recent days, all of the Slurm machines within the
entire DOOP fleet have malfunctioned, due to some kind of software thing.
We have reason to believe that this was the doing of the evil Sprite people
of Cola 3, and we plan to destroy their entire civilization. But doing so
without the refreshing taste of Slurm would undo years of training. It falls
to you, the esteemed members of the High-fructose Alliance League to solve
the problem.
All we have left of the Slurm software is the unit tests used to make sure
that the Slurm machines are battle ready.
If you pull this off, I don't know, we'll give you a medal or something.
If you fail, throats will be dry throughout the galaxy.
God speed.
Your inspiring and well-chiseled leader,
Zapp Branningan
"""
class SlurmTests(unittest.TestCase):
def setUp(self):
self.soda = SlurmMachine(slurm=10)
self.soda.on = True
def test_init(self):
soda = self.soda
self.assertEqual(soda.selection, ['slurm'])
self.assertEqual(soda.total, 10)
self.assertEqual(soda.state, dict(slurm=10))
self.assertEqual(soda.on, False)
def test_selection_addition(self):
soda = self.soda
soda.selection = ['slurm', 'powerthirst']
self.assertEqual(soda.total, 10)
self.assertEqual(soda.state, {'slurm': 10, 'powerthirst': 0})
self.assertEqual(soda.on, False)
def test_selection_subtraction(self):
soda = SlurmMachine(slurm=10, powerthirst=10)
soda.selection = ['slurm']
self.assertEqual(soda.total, 10)
self.assertEqual(soda.state, {'slurm': 10})
self.assertEqual(soda.on, False)
def test_selection_no_duplicates_init(self):
soda = SlurmMachine(slurm=10, powerthirst=0, Slurm=5)
self.assertItemsEqual(soda.selection, ['slurm', 'powerthirst'])
self.assertDictEqual(soda.state, {'slurm': 15, 'powerthirst': 0})
def test_selection_no_duplicates_selection(self):
soda = self.soda
soda.selection = ['slurm', 'Slurm']
self.assertItemsEqual(soda.selection, ['slurm'])
def test_dispense_DNE_returns_None(self):
soda = self.soda
self.assertIs(soda.dispense('water'), None)
def test_dispense_off_returns_None(self):
soda = self.soda
soda.on = False
self.assertIs(soda.dispense('slurm'), None)
def test_dispense_slurm_returns_True(self):
soda = self.soda
self.assertIs(soda.dispense('slurm'), True)
def test_dispense_empty_returns_False(self):
soda = SlurmMachine(slurm=0)
self.assertIs(soda.dispense('slurm'), False)
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment