Skip to content

Commit

Permalink
INTU-1187 | Add unit test for the gesture class
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravi Sinha committed Apr 12, 2017
1 parent bb8ca8a commit 4c5fd30
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions self/gestures/gesture.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ def __init__(self, gesture_id, instance_id):

def get_gesture_id(self):
''' Return the gesture ID associated with this gesture '''
if self.gesture_id is None or self.gesture_id == '':
raise Exception('gesture_id should not be empty or None')
return self.gesture_id

def get_instance_id(self):
''' Return the instance ID associated with this gesture '''
if self.instance_id is None or self.instance_id == '':
raise Exception('instance_id should not be empty or None')
return self.instance_id
40 changes: 40 additions & 0 deletions tests/GestureTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
''' Unit test for the Gesture class '''

import unittest
import sys
sys.path.append('../')
from self.gestures.gesture import Gesture

class TestGesture(unittest.TestCase):
''' A bunch of unit tests that test the basic functionality of the Gesture
class '''

def test_get_instance(self):
''' Verify that the object gets instantiated correctly with default
values '''
test_gesture = Gesture(1, 2)
self.assertEqual(test_gesture.get_gesture_id(), 1)
self.assertEqual(test_gesture.get_instance_id(), 2)

def test_gesture_id_sanity(self):
''' Should not allow a blank or None gesture ID to go unnoticed '''
test_gesture = Gesture(None, 2)
with self.assertRaises(Exception):
test_gesture.get_gesture_id()

test_gesture = Gesture('', 2)
with self.assertRaises(Exception):
test_gesture.get_gesture_id()

def test_instance_id_sanity(self):
''' Should not allow a blank or None instance ID to go unnoticed '''
test_gesture = Gesture(1, None)
with self.assertRaises(Exception):
test_gesture.get_instance_id()

test_gesture = Gesture(1, '')
with self.assertRaises(Exception):
test_gesture.get_instance_id()

if __name__ == '__main__':
unittest.main()

0 comments on commit 4c5fd30

Please sign in to comment.