Skip to content

Commit

Permalink
improve input validation for variables and dcares
Browse files Browse the repository at this point in the history
  • Loading branch information
Kumbong committed Jun 27, 2019
1 parent c310549 commit 21a1395
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions qmccluskey.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,24 @@ def representsInt(s):
for dc in dcares:
if (dc and not representsInt(dc)) or ((dc and representsInt(dc)) and int(dc) < 0):
sys.exit('Error : Integer values expected for don\'t cares')

#a term cannot be a don't care and a minterm at the same time
if dc in minterms:
sys.exit('Error: A term cannot be a minterm and a don\'t care at the same time')

else:
dcares = []

##################################add validation for variables here ####################
if args.variables:
variables = args.variables.split(',')

#filter out duplicates in the variables entered


#if there were duplicate terms then let the user know
if len(variables) != len(list(set(variables))):
sys.exit("Error: Duplicate terms not allowed for variables")
#make sure the variables entered are enough to represent the expression
#else raise a value error exception and close the program

Expand Down

0 comments on commit 21a1395

Please sign in to comment.