# [EXAM STARRED] More Test Cases

 10 6 Here are the test cases I used for testing my solutions to starred problems. would be helpful if you don't want to spend time design your own test cases. Just copy and paste the "Input" part at the end of your code. Hope you enjoy it! 1 - Reachability Input: graph = {'a': ['b', 'c'], 'b': ['a', 'c'], 'c': ['b', 'd'], 'd': ['a'], 'e': ['a']} print reachable(graph, 'a') print reachable(graph, 'd') print reachable(graph, 'e') graph2 = {'1': ['2', '3'], '2': [], '3': ['5', '7'], '4': ['3'], '5': ['4'], '6': ['3', '5', '7'], '7': ['1', '6']} for i in range(len(graph2)): print reachable(graph2, str(i + 1)) graph3 = {'1': ['2', '4', '5'], '2': [], '3': ['6'], '4': ['3', '7', '8'], '5': ['7'], '6': ['9', '10'], '7': ['6', '11'], '8': ['10', '11'], '9': [], '10': ['9', '11'], '11' :[], '12': []} for i in range(len(graph3)): print reachable(graph3, str(i + 1))  Output: ['a', 'c', 'd', 'b'] ['d', 'a', 'c', 'b'] ['e', 'a', 'c', 'd', 'b'] ['1', '3', '7', '6', '5', '4', '2'] ['2'] ['3', '7', '6', '1', '2', '5', '4'] ['4', '3', '7', '6', '1', '2', '5'] ['5', '4', '3', '7', '6', '1', '2'] ['6', '7', '1', '2', '5', '4', '3'] ['7', '6', '5', '4', '3', '1', '2'] ['1', '5', '7', '11', '6', '10', '9', '4', '8', '3', '2'] ['2'] ['3', '6', '10', '11', '9'] ['4', '8', '11', '10', '9', '7', '6', '3'] ['5', '7', '11', '6', '10', '9'] ['6', '10', '11', '9'] ['7', '11', '6', '10', '9'] ['8', '11', '10', '9'] ['9'] ['10', '11', '9'] ['11'] ['12']  2 - Spelling Correction Input: print edit_distance('', '') print edit_distance('a', 'a') print edit_distance('God', 'good') print edit_distance('city', 'cities') print edit_distance('chance', 'charge') print edit_distance('programming', 'programmer') print edit_distance('destruct', 'constructor') print edit_distance('trace-back', 'traceback') print edit_distance('Pepsi', 'Coca-Cola') print edit_distance('Coke', 'Coca-Cola') print edit_distance('Kitamura', 'Kitahara') print edit_distance('James Joyce', 'Rolls-Royce') print edit_distance('Pneumothorax', 'Pneumonoultramicroscopicsilicovolcanoconiosis') print edit_distance('ATCCTAGCCATGCAATGACATTG', 'ACTCTAGCCATGCATTGACATGT') print edit_distance('LCLYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFSAIPYIGTNLVEWIWGGFSVDKATLNRFFAFHFILPFTMVALAGVHLTFLHETGSNNPLGLTSDSDKIPFHPYYTIKDFLGLLILILLLLLLALLSPDMLGDPDNHMPADPLNTPLHIKPEWYFLFAYAILRSVPNKLGGVLALFLSIVILGLMPFLHTSKHRSMMLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGXIENY', 'LCTYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFSAIPYIGTNLVEWIWGGFSVDKATLRFLAFHFILPFTMVALAGVHLTFLHETGSNNPLGLTSDSDKIPFHPYYTIKDFLGLLILILLLLLLALLSPDMLGDPDNHMPADPLNTPLHIKLEWYFLFAYAILRSVPNKLGGVLALFFSIVILGLMPFLHTSKHRSMGLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGXXIENY')  Output: 0 0 2 3 2 3 5 1 9 7 2 6 36 5 7  3 - Multiword Queries Input: cache = { 'http://localhost/index.html': """ OpenGL 2.0
ARB
""", 'http://localhost/01.html': """ OpenGL 2.0 was originally conceived by 3Dlabs to address concerns that OpenGL was stagnating and lacked a strong direction. 3Dlabs proposed a number of major additions to the standard. Most of these were, at the time, rejected by the ARB or otherwise never came to fruition in the form that 3Dlabs proposed. However, their proposal for a C-style shading language was eventually completed, resulting in the current formulation of GLSL (the OpenGL Shading Language, also slang). Like the assembly-like shading languages that it was replacing, it allowed the programmer to replace the fixed-function vertex and fragment pipe with shaders, though this time written in a C-like high-level language. The design of GLSL was notable for making relatively few concessions to the limitations of the hardware then available; this hearkened back to the earlier tradition of OpenGL setting an ambitious, forward-looking target for 3D accelerators rather than merely tracking the state of currently available hardware. The final OpenGL 2.0 specification includes support for GLSL. OpenGL 2.0 added support for a true, GPU-based assembly language called ARB (designed by the Architecture Review Board), which would become the standard for vertex and fragment shaders. Cards released with OpenGL 2.0 were the first to offer user-programmable shaders. """, 'http://localhost/02.html': """ Subsequent high-level shading languages sometimes compile to this ARB standard. While 3D developers are now more likely to use a C-like, high-level shading language for GPU programming, ARB assembly has the advantage of being supported on a wide range of hardware. Note however that some features, such as loops and conditionals, are not available in ARB assembly, and using them requires to adopt either the NV_gpu_program4 extension, or the GLSL shading language. Most non-nVidia OpenGL implementations do not provide the nVidia ARB assembly extension and do not offer any other way to access all the shader features directly in assembly, forcing the use of GLSL even for machine generated shaders where assembly would be more appropriate. """, 'http://localhost/03.html': """ Cg (short for C for Graphics) is a high-level shading language developed by Nvidia in close collaboration with Microsoft for programming vertex and pixel shaders. It is very similar to Microsoft's HLSL. Cg is based on the C programming language and although they share the same syntax, some features of C were modified and new data types were added to make Cg more suitable for programming graphics processing units. This language is only suitable for GPU programming and is not a general programming language. The Cg compiler outputs DirectX or OpenGL shader programs. """, 'http://localhost/04.html': """ The High Level Shader Language or High Level Shading Language (HLSL) is a proprietary shading language developed by Microsoft for use with the Microsoft Direct3D API. It is analogous to the GLSL shading language used with the OpenGL standard. It is the same as the Nvidia Cg shading language, and it was developed alongside it. HLSL programs come in three forms, vertex shaders, geometry shaders, and pixel (or fragment) shaders. A vertex shader is executed for each vertex that is submitted by the application, and is primarily responsible for transforming the vertex from object space to view space, generating texture coordinates, and calculating lighting coefficients such as the vertex's tangent, binormal and normal vectors. When a group of vertices (normally 3, to form a triangle) come through the vertex shader, their output position is interpolated to form pixels within its area; this process is known as rasterisation. Each of these pixels comes through the pixel shader, whereby the resultant screen colour is calculated. """ } index2, graph2 = crawl_web('http://localhost/index.html') print multi_lookup(index2, ['OpenGL']) print multi_lookup(index2, ['GLSL']) print multi_lookup(index2, ['high-level']) print multi_lookup(index2, ['vertex']) print multi_lookup(index2, ['vertex', 'shader']) print multi_lookup(index2, ['GPU', 'programming']) print multi_lookup(index2, ['assembly', 'language']) print multi_lookup(index2, ['shading', 'languages']) print multi_lookup(index2, ['C', 'programming', 'language']) print multi_lookup(index2, ['shading', 'language']) print multi_lookup(index2, ['shading', 'languages']) print multi_lookup(index2, ['GLSL', 'shading', 'language']) print multi_lookup(index2, ['Cg', 'shading', 'language']) print multi_lookup(index2, ['HLSL', 'shading', 'language']) print multi_lookup(index2, ['proprietary', 'shading', 'language'])  Output: ['http://localhost/index.html', 'http://localhost/04.html', 'http://localhost/03.html', 'http://localhost/02.html', 'http://localhost/01.html'] ['http://localhost/04.html', 'http://localhost/02.html', 'http://localhost/01.html'] ['http://localhost/03.html', 'http://localhost/02.html', 'http://localhost/01.html'] ['http://localhost/04.html', 'http://localhost/03.html', 'http://localhost/01.html'] ['http://localhost/04.html'] ['http://localhost/03.html'] ['http://localhost/01.html'] ['http://localhost/02.html', 'http://localhost/01.html'] ['http://localhost/03.html'] ['http://localhost/index.html', 'http://localhost/04.html', 'http://localhost/03.html', 'http://localhost/02.html', 'http://localhost/01.html'] ['http://localhost/02.html', 'http://localhost/01.html'] ['http://localhost/04.html'] ['http://localhost/index.html'] ['http://localhost/index.html'] ['http://localhost/04.html']  asked 06 Apr '12, 22:40 Xiaomo (Mort... 240●3●4●11 accept rate: 0% how did you get print edit_distance('Pneumothorax', 'Pneumonoultramicroscopicsilicovolcanoconiosis') == 36 ? I get 37, which is both the output of my program and my own consideration: len(microscopicsilicovolcanoconiosis) + edit_distance('tho','noult') = 32 + 5 = 37 (07 Apr '12, 22:09) Andriy Petra... @proftobes For this case, you can't simply count the length of "microscopicsilicovolcanoconiosis" as a whole word. See this result I got: (36 steps)  Pneumothorax -> Pneumonoulthorax: 4 insertions  Pneumonoulthorax -> Pneumonoultrarax: 2 substitutions Pneumonoultrarax -> Pneumonoultramicrax: 3 insertions Pneumonoultramicrax -> Pneumonoultramicroscopicsilicovolcax: 17 insertions Pneumonoultramicroscopicsilicovolcax -> Pneumonoultramicroscopicsilicovolcan: 1 substitutions Pneumonoultramicroscopicsilicovolcan -> Pneumonoultramicroscopicsilicovolcanoconiosis: 9 insertions  (08 Apr '12, 07:16) Xiaomo (Mort... you're right. Thanks! (08 Apr '12, 09:36) Andriy Petra...

 0 3 - Multiword Queries output for this test case print multi_lookup(index2, ['Cg', 'shading', 'language']) is =>['http://localhost/index.html', 'http://localhost/04.html'] output for this test case print multi_lookup(index2, ['GLSL', 'shading', 'language']) is =>['http://localhost/04.html', 'http://localhost/02.html']  ThanQ very much for testcases :) answered 06 Apr '12, 23:39 Chitirala Na... 207●3●6●17
 0 Dear colleagues, First of all, thanks to Mort Yao for your test cases. After running your test cases for exercise 7.2s I saw everything went ok but I noticed that there is one case that it seems it was not covered in your tests : print edit_distance('anac', 'nacho') == 3 #For this case, the best solution includes a deletion for first char and two additions.  I hope this can help. answered 07 Apr '12, 13:53 Ignacio-1 12●2
 0 Mort Yao, thank you for posting these test cases. However, I believe some of them from 7.3 may be wrong: print multi_lookup(index2, ['GPU', 'programming'])  Invoking this code should yield: ['http://localhost/03.html', 'http://localhost/02.html']  If you check the cache, you will see that the keywords are found in both these pages. answered 07 Apr '12, 22:35 Equuleus 94●1●5●8 1 this is an interesting edge case b/c in one of those pages the string is "GPU programming," with a comma on the end. See this thread for discussion on whether punctuation marks should be ignored when judging for a match: http://www.udacity-forums.com/cs101/questions/57502/final-exam-73-starred-punctuation-marks (07 Apr '12, 23:43) Kevin Troy
 0 Thanks very much.. It helped me found a bug and I fixed it. :) answered 08 Apr '12, 00:18 Chris1991 1.5k●3●16
 0 Thanks for the test cases. answered 09 Apr '12, 06:34 ilikeudacity-2 717●3●18●29
 0 @mort-yao, What is the expected output in the reachability problem if the starting node is not in the graph? have you considered this in your tests? answered 09 Apr '12, 07:19 john32 296●4●9●15 that is another edge case. don't think this is something we have to consider, since the problem didn't tell what is the expected output if the starting node is not in the graph (return a None, [], the staring node itself or just throw an exception). (09 Apr '12, 10:07) Xiaomo (Mort...
 0 For the multi_lookup today making a revision of my code I found that mine wouldn't have passed: print multi_lookup(index, []) It was throwing an error that I had to prevent I don't know if the rest of you have tested it... answered 09 Apr '12, 07:31 SafetyCar 521●2●8●12
Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

×15,214
×664
×32
×4