Login Register






Unit Test filter_list
Author
Message
Unit Test #1
Hello, please i am having problem writing unit test for learnpythonthehardway the ex48 i have tried everything i just keep having assert_equal(lexicon.scan("bear"), [('noun', ‘bear')]) AssertionError: 'noun' != [('noun’, 'bear')] i have been trying for weeks i need help please, the exercises below

http://learnpythonthehardway.org/book/ex48.html

if you need my code please let me know so that it can be corrected .

Reply

RE: Unit Test #2
Hello, please can someone help me still? the place i am having problem is the assert_equal can someone put me through?

Reply

RE: Unit Test #3
(11-26-2012, 05:51 AM)Pain Wrote: Hello, please i am having problem writing unit test for learnpythonthehardway the ex48 i have tried everything i just keep having assert_equal(lexicon.scan("bear"), [('noun', ‘bear')]) AssertionError: 'noun' != [('noun’, 'bear')] i have been trying for weeks i need help please, the exercises below

http://learnpythonthehardway.org/book/ex48.html

if you need my code please let me know so that it can be corrected .

lexicon.scan() doesn't return a list of tupels as expected. It returns a string instead. So you did something wrong in your scan() code.
lexicon.scan("bear") shall return [('noun’, 'bear')]. That is a list which contains exactly one tupel: ('noun', 'bear'). Make sure that you return the correct data type.
Post your code here, if you still have problems.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: Unit Test #4
Hello, thanks for your reply code below still getting the same problem

lexi = {'north': 'direction', 'south': 'direction', 'west': 'direction',
'east': 'direction', 'down': 'direction', 'up': 'direction',
'left': 'direction', 'right': 'direction', 'back': 'direction',
'go': 'verb', 'stop': 'verb', 'kill': 'verb', 'eat': 'verb',
'the': 'stop', 'in': 'stop', 'of': 'stop', 'from': 'stop',
'at': 'stop', 'it': 'stop', 'bear': 'noun', 'door': 'noun',
'princess': 'noun', 'cabinet': 'noun', '1234': 'number',
'3': 'number', '91234': 'number'
}

def words(stuff):
stuff = raw_input('> ')
words = stuff.split()

for word in words:
a_word = (('direction', 'north'), ('verb', 'go'), ('stop', 'the'))
b_word = (('noun', 'bear'), ('number', '1234'))
word = [a_word, b_word]

def scan(word):
word = lexi.get(word, 'error')
return word

Reply

RE: Unit Test #5
The indentation level in Python is important for the logic of the program. I am not able to read your program, if you don't provide the code with your proper indentation. Please use code-tags like this: [.code]your code[/code] (remove the dot)

Also try to understand the error message and try to fix your code according to this. You have to return the correct data type. You can not return a string where a list of tupels is requested.

Code:
word = lexi.get(word, 'error')

This will make word a string, not a list of tupels. Let me explain by example.
You have a dictionary like this:

Code:
lexi = {'north': 'direction', 'south': 'direction'}

Now you do this, where 'north' is the key and 'error' the default value:

Code:
word = lexi.get('north', 'error')

The computer now looks up 'north' in the dictionary and returns the value of it. In this case it finds the value 'direction'. So your variable word will have the value 'direction' which is a string.
Again: You don't want a single string, you shall return a list of tupels.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: Unit Test #6
Hello, thanks for your response yeah that's the problem i am facing i don't really understand how i can return the tuple cause i tried everything but i just keep getting error i know i did something wrong but i don't know what it's this is why i am asking for help so that it can be fix i am lost.
Code:
lexi = {'north': 'direction', 'south': 'direction', 'west': 'direction', 'east': 'direction', 'down': 'direction', 'up': 'direction', 'left': 'direction', 'right': 'direction', 'back': 'direction', 'go': 'verb', 'stop': 'verb', 'kill': 'verb', 'eat': 'verb', 'the': 'stop', 'in': 'stop', 'of': 'stop', 'from': 'stop', 'at': 'stop', 'it': 'stop', 'bear': 'noun', 'door': 'noun', 'princess': 'noun', 'cabinet': 'noun', '1234': 'number', '3': 'number', '91234': 'number' } def words(stuff): stuff = raw_input('> ') words = stuff.split() for word in words: a_word = (('direction', 'north'), ('verb', 'go'), ('stop', 'the')) b_word = (('noun', 'bear'), ('number', '1234')) word = [a_word, b_word] def scan(word): word = lexi.get(word, 'error') return word

Reply

RE: Unit Test #7
You have to:
1. Look for the user input in the lexicon values
2. Put every tupel of the lexicon in a list that has a value that fits to the user input
3. Return the list of tupels

How to do this:
1.
One possibility to iterate through a dictionary is this:

Code:
for key, value in lexicon.iteritems():

Within this loop you check if value fits to the user input. I.e. if you called scan("bear") you have to check if value == 'bear'.

2.
If value == 'bear', you add the tupel to a list, which will contain all your results:

Code:
tupel = (key, value) list.append(tupel)

3.
Return your list of tupels and you are done
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: Unit Test #8
Hello, thanks for your help this is how i did it but i am still getting the same problem but can you check it out ? cause it seen i did something wrong again
Code:
def words(stuff): stuff = raw_input('> ') words = stuff.split() for word, words in lexi.iteritems(): a_word = (('direction', 'north'), ('verb', 'go'), ('stop', 'the')) b_word = (('noun', 'bear'), ('number', '1234')) word = [a_word, b_word] return word if word == sentence: list.append(sentence) def scan(sentence): return lexi.get(sentence, 'error')

Reply

RE: Unit Test #9
You have to return the list instead of that:

Code:
return lexi.get(sentence, 'error')

This doesn't make any sense at all:
Code:
for word, words in lexi.iteritems(): a_word = (('direction', 'north'), ('verb', 'go'), ('stop', 'the')) b_word = (('noun', 'bear'), ('number', '1234')) word = [a_word, b_word] return word

I don't know what you are trying to do here. Start over and just follow the instructions I gave you.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: Unit Test #10
Hello, thanks for your help i do appreciate but it seen i am unable to get it right still thanks .

Reply