Class: TestWWS

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/test/WWS_test_cases.rb

Overview

WebWordSorter Unit Test Class

Description

This class is responsible for ensuring all methods of the WebWordSorter class are functioning properly. Any modifications to the current class methods should be tested using this class. Any additional methods added to the WedWordSorter class should also have a test designed for them to ensure future stability, and managable code.

Instance Method Summary collapse

Instance Method Details

#test_crawlObject

Test Description

This method tests that all links of a page are properly being collected by the anemone crawler. www.example.com is crawled in a way known to be stable and its output is compared to the output from the WebWordSorter class.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/test/WWS_test_cases.rb', line 26

def test_crawl
	
	pages = 0 

	Anemone.crawl("http://www.example.com") do |anemone|
	anemone.on_every_page do |page|

  			pages = (pages + 1)
	end	
		end

	expected  = WebWordSorter.new.crawler ("http://www.example.com")
	assert_equal expected.length, pages

end

#test_pages_to_stringObject

Test Description

This method tests that all webpages are prooerly being converted to strings. The two websites used here are avaliable for testing puropses exclusively. The combined stirng that should be returned from these sites is known, and is compared to that string that is returned by the WebWordSorter class.



48
49
50
51
52
53
54
55
56
57
# File 'lib/test/WWS_test_cases.rb', line 48

def test_pages_to_string

	test_array = ["http://129.24.149.151/test0.html", "http://129.24.149.151/test1.html" ]
	test_string ="This is a test string for the caanes webpage word sort interview project.\ntest     test   test /!@$\n" 

	expected = WebWordSorter.new.pages_to_string test_array

	assert_equal(expected, test_string)

end

#test_parse_stringObject

Test Description

This method tests to ensure all markup and charecters are parsed correctly. everything but letters and single spaces should be removed and returned. A string is given with a known output. The string is passed to the WebWordSorter class and what is returend is compared to the known correct output.



65
66
67
68
69
70
71
72
73
74
# File 'lib/test/WWS_test_cases.rb', line 65

def test_parse_string

	test_input = "Word dr. !@ %^&$( another word CAPS lowercase  1   2345 67     \n newline! oh no!"
	test_string = "Word dr another word CAPS lowercase newline oh no "

	expected = WebWordSorter.new.parse_string test_input

	assert_equal(expected, test_string)

end

#test_spell_checkObject

Test Description

This method ensures that only true words (as determined by the dictionry file used) are kept in the final array to be sorted. An array of words and non words is given with an array or the known real words. The array of words and non words is passed to the WebWordSorter class and the result is compared to the array of known words. Test will fail unless they are identical.



101
102
103
104
105
106
107
108
109
# File 'lib/test/WWS_test_cases.rb', line 101

def test_spell_check

	test_input = ['valid','novalid','test','words','sukess','America', 'a', 'ke', 'I','o','probingisaclassofattackswhereanattackerscansanetworktogatherinformationor', 'borderradius']
	test_array= ['valid','test','words','America','a','I','o']

	expected = WebWordSorter.new.spell_check test_input

	assert_equal(expected, test_array)
end

#test_spilt_uniqObject

Test Description

This method ensures that the conversion of the string to an array is correct. A string is given with a known aoutput array. The string is passed to the WebWordSorter class and then compared with the known correct output lenght to verify the string was properly split.



83
84
85
86
87
88
89
90
91
# File 'lib/test/WWS_test_cases.rb', line 83

def test_spilt_uniq

	test_input = "one two three three four five five five  abc abc abc "

	expected = WebWordSorter.new.split_uniq test_input

	assert (expected.length == expected.uniq.length)

end

#test_stooge_sortObject

Test Description

This method ensures that the final output is sorted properly. An unsorted array is passed to an insrance of the WebWord sorter and the output is compared to a known sorted version of the given array.



117
118
119
120
121
122
123
124
125
126
# File 'lib/test/WWS_test_cases.rb', line 117

def test_stooge_sort

	test_input = ['apple','orange','pear','grape','watermelon','fig','tomato','date']
	test_array= ['fig','pear','date','grape','apple','tomato','orange', 'watermelon']

	expected = WebWordSorter.new.stooge_sort test_input

	assert_equal(expected, test_array)

end