Coding project UNQ C9 unit test has a bug

The function should return a set, but the test code assumes it is a list.

Another thing I do not understand is: I intentionally discard the original word to trigger this bug. If do not discard it, I have 18 tests passed but 2 failed. This function just calls previously implemented edit_one_letter(), which has passed all unit tests. Is there any bug in my code, or it is also a bug in the unit tests?

# Test your function
w1_unittest.test_edit_two_letters(edit_two_letters)
Wrong output type.
	Expected: 2654.
	Got: 2653.
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
~/work/w1_unittest.py in test_edit_two_letters(target)
   1622             assert sorted(list(result))[:10] == sorted(
-> 1623                 test_case["expected"]["expected_head"]
   1624             )

AssertionError: 

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-43-3b36c6903fa4> in <module>
      1 # Test your function
----> 2 w1_unittest.test_edit_two_letters(edit_two_letters)

~/work/w1_unittest.py in test_edit_two_letters(target)
   1629                     "name": test_case["name"],
   1630                     "expected": test_case["expected"]["expected_head"],
-> 1631                     "got": result[:10],
   1632                 }
   1633             )

TypeError: 'set' object is not subscriptable

Test seems fully bugged for that notebook. On the last exercice, i got that unit test response :

Distance matrix has wrong values.
	Expected: [[ 0  2  4  6  8 10]
 [ 2  0  2  4  6  8]
 [ 4  2  0  2  4  6]
 [ 6  4  2  0  2  4]
 [ 8  6  4  2  3  5]].
	Got: [[0 1 2 3 4 5]
 [1 0 2 4 6 7]
 [2 2 0 2 4 6]
 [3 4 2 0 2 4]
 [4 6 4 2 3 5]].
 15  Tests passed
 1  Tests failed```
Matrices should all start as 0 to n range on the first row and column. 
I do have another unit test not working on edit_two _letter_function 

Wrong output type.
Expected: 7130.
Got: 7154.
Wrong output type.
Expected: 14206.
Got: 14352.
18 Tests passed
2 Tests failed

wich I dont understand since every other unit test before is working.
1 Like

I have exactly the same result if I do not discard the original word (to trigger the set access bug).

Can any TA or instructor reply to the testing bug question?

@Mubsi Mubsi, can you reply to this question or forward to any other TAs?

UNQ_C11 unit test has also a bug. I got:

Distance matrix has wrong values.
	Expected: [[ 0  2  4  6  8 10]
 [ 2  0  2  4  6  8]
 [ 4  2  0  2  4  6]
 [ 6  4  2  0  2  4]
 [ 8  6  4  2  3  5]].
	Got: [[0 1 2 3 4 5]
 [1 0 2 4 6 7]
 [2 2 0 2 4 6]
 [3 4 2 0 2 4]
 [4 6 4 2 3 5]].
 15  Tests passed
 1  Tests failed

The expected initializations (both row 0 and column 0) are wrong .

1 Like

Hi @larryleguo

I suspect you hard coded rep_cost value. Please check what happens when your function receives different arguments. If the problem persist, please message me your notebook I will look into it.

1 Like

I found my mistake on that one, I was not using the allow_switch parameter in edit two letters.

4 Likes

Hi, Arvyzukai,

I did not hard code the rep_cost value. Enclosed is my notebook.
C2_W1_Assignment.ipynb (84.4 KB)

Thanks, this is also my issue.

Thanks, this solved my issue as well.

Hi,

Im having the same problem on C11, I don’t have rep_cost hardcoded. Also seems weird that the test expects the row 0 to be [ 0 2 4 6 8 10]; how would this happen? Isn’t it always initialized as [0 1 2 3 4 5]?

how can I post a question relating to course 1 of NLP?
Sorry it does not answer your own post, but I don’t know where else to post this.

Hi, Arvyzukai,

Have you had a chance to take a look st my notebook? Thanks.

No its not. Remember :
row means how many cost you need for deleting words in the source to be similar to the target (the target’s length at row 0 is zero).
col means how many cost you need for inserting words into the source to be similar to the target (the source’s length at col 0 is zero).

Remember :
row means how many cost you need for deleting words in the source to be similar to the target (the target’s length at row 0 is zero).
col means how many cost you need for inserting words into the source to be similar to the target (the source’s length at col 0 is zero).

You have to take into account ins_cost and del_cost when initialising row 0 and col 0 of D.

Great tip. This fixed the issue for me. Many thanks!!