Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Solution for Assignment 1 #57

Closed
wants to merge 10 commits into from

Conversation

LoneWolfKJ
Copy link

No description provided.

Copy link
Owner

@kaustubh-karkare kaustubh-karkare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start!

return r'^[0-9]+$'
return r'^\w+$'

OPTIONS = Parser()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to test stuff like this, you typically should do this from a separate file?
That way, you have a clear separate between library vs application.

self.arguments.append((str(command), str(value)))
if len(arg_pair) == 1:
self.validate(command, 'True')
self.arguments.append((str(command), 'True'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Why do you need to save this in a class property like self.arguments? Why not something simpler like local variable?
  • How about use adding the value to a dict directly, instead of using tuples as an intermediate step?

"""Ensures that command and value are valid"""
currently_valid = False
for option in self.options:
if bool(re.match(option.option_name, str(command), re.IGNORECASE)):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're just doing a string contains check.

if option.option_name in command

if required:
self.required_options.append(option_being_added)

def add_mutually_exclusive_options(self, option1, option2):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There can be more than 2 mutually exclusive things.

option_being_added = Option(option_name, option_description, option_type)
self.options.append(option_being_added)
if required:
self.required_options.append(option_being_added)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a separate list, why not an extra flag in the options object?

Copy link
Owner

@kaustubh-karkare kaustubh-karkare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! A bit more cleanup possible, which is optional, but you can now close this PR.

def validate_type_and_existence(self, command, value):
"""Ensures that command and value are valid"""
currently_valid = False
for option in self.options:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a dict instead of a list will reduce complexity here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if option.is_required is True:
currently_valid = False
for commands in arguments:
if commands == option.option_name:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for option in self.options:
  if option.option_name in arguments:

option_being_added = Option(option_name, option_description, option_type, required)
self.options.append(option_being_added)

def add_mutually_exclusive_options(self, exclusive_options_list):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add a required flag here also? So that we can conditionally require that at least one of the mutually exclusive options are provided.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isRequired - bool value to check if option is required or not
"""
def __init__(self, option_name, option_description, option_type, is_required):
self.option_name = option_name
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we access this as option.option_name, we could have just called it name (ie - option.name).

@LoneWolfKJ LoneWolfKJ closed this Sep 1, 2019

def add_mutually_exclusive_options(self, exclusive_options_list, is_one_required):
"""adds conflicting commands to a list as a tuple"""
self.mutually_exclusive_options.append((exclusive_options_list, is_one_required))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, the name mutually_exclusive_options is not enough to indicate what it contains now.
Just something to be aware of :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants