Ejemplo n.º 1
0
    def test_get_top(self):
        """Should return a reference to top node on stack if there is one"""

        test = SearchPath(SearchPathHelper.alphabets)
        test._add_node(SearchNode(SearchNodeHelper.alphabet))
        topnode = SearchNode(SearchNodeHelper.alphabet)
        test._add_node(topnode)

        resultnode = test._get_top()
        self.assertEquals(resultnode, topnode)
Ejemplo n.º 2
0
 def test_removeOption_noneLeft(self):
     """removeOption should cull options and return F when none left."""
     
     test = SearchNode(SearchNodeHelper.alphabet)
     num_options = len(test.Options)
     
     #removeOption num_options times: that should get 'em all
     for i in xrange(num_options): some_left = test.removeOption()
     
     #return value should be false (no options remain)
     self.assertEqual(some_left, False)        
Ejemplo n.º 3
0
 def test_removeOption_noneLeft(self):
     """removeOption should cull options and return F when none left."""
     
     test = SearchNode(SearchNodeHelper.alphabet)
     num_options = len(test.Options)
     
     #removeOption num_options times: that should get 'em all
     for i in xrange(num_options): some_left = test.removeOption()
     
     #return value should be false (no options remain)
     self.assertEqual(some_left, False)        
Ejemplo n.º 4
0
    def test_add_node_subsequent(self):
        """add_node should correctly add additional nodes and up top index."""

        test = SearchPath(SearchPathHelper.alphabets, \
                SearchPathHelper.standard_forbid_seq)
        test_node = SearchNode(SearchNodeHelper.alphabet)
        test_node2 = SearchNode(SearchNodeHelper.alphabet)
        test._add_node(test_node)
        test._add_node(test_node2)
        self.assertEquals(len(test._path_stack), 2)
        self.assertEquals(test._top_index, 1)
Ejemplo n.º 5
0
    def test_removeOption_someLeft(self):
        """removeOption should cull options and return T when some left."""

        #create a search node and get its current value
        test = SearchNode(SearchNodeHelper.alphabet)
        last_val = test.Value

        some_left = test.removeOption()

        #new current value must be different from old
        #and return value must be true
        self.assertNotEqual(test.Value, last_val)
        self.assertEqual(some_left, True)
Ejemplo n.º 6
0
 def test_removeOption_someLeft(self):
     """removeOption should cull options and return T when some left."""
     
     #create a search node and get its current value
     test = SearchNode(SearchNodeHelper.alphabet)
     last_val = test.Value
     
     some_left = test.removeOption()
     
     #new current value must be different from old
     #and return value must be true
     self.assertNotEqual(test.Value, last_val)
     self.assertEqual(some_left, True)
Ejemplo n.º 7
0
    def test_options(self):
        """Should return a copy of real options"""

        test = SearchNode(SearchNodeHelper.alphabet)
        optionsA = test.Options
        del optionsA[0]
        optionsB = test.Options
        self.assertNotEqual(len(optionsA), len(optionsB))
Ejemplo n.º 8
0
    def test_init_noArg(self):
        """Init should correctly set private properties w/no arg"""
        correct_result = str(SearchNodeHelper.alphabet)

        test = SearchNode(SearchNodeHelper.alphabet)
        options = test.Options
        options.sort()
        real_result = str(options)
        self.assertEquals(real_result, correct_result)
Ejemplo n.º 9
0
    def test_add_node_first(self):
        """add_node should correctly add first node and increase top index."""

        test = SearchPath(SearchPathHelper.alphabets, \
                SearchPathHelper.standard_forbid_seq)
        test_node = SearchNode(SearchNodeHelper.alphabet)
        test._add_node(test_node)
        self.assertEquals(len(test._path_stack), 1)
        self.assertEquals(test._top_index, 0)
Ejemplo n.º 10
0
    def test_findAllowedOption_currentAllowed(self):
        """Should return true when current option is allowed"""

        #searchpath with no forbidden seqs, so anything should work
        test = SearchPath(SearchPathHelper.alphabets)
        test._add_node(SearchNode(SearchNodeHelper.alphabet))
        allowed_found = test.findAllowedOption()

        self.assertEquals(allowed_found, True)
Ejemplo n.º 11
0
    def test_check_forbidden_seqs_none(self):
        """Should return False if path includes no forbidden seqs"""

        #a seq that isn't in the standard fixed forbidden lib
        allowed_seq = ["C", "U", "A", "T"]

        test = SearchPath(SearchPathHelper.alphabets, \
                SearchPathHelper.standard_forbid_seq)
        test._add_node(SearchNode(SearchNodeHelper.alphabet))

        #add more values, and cheat so as to make them something known
        for known_val in allowed_seq:
            curr_node = SearchNode(SearchNodeHelper.alphabet)
            curr_node._options[0] = known_val  #torque the node's innards
            test._add_node(curr_node)
        #next bad_val

        real_result = test._check_forbidden_seqs()
        self.assertEquals(real_result, False)
Ejemplo n.º 12
0
    def test_check_forbidden_seqs_fixed(self):
        """Should return True if path includes a fixed forbidden seq"""

        forbidden_seq = ["G", "U", "A"]
        user_input = ["".join(forbidden_seq)]
        user_input.extend(SearchPathHelper.standard_forbid_seq)

        test = SearchPath(SearchPathHelper.alphabets, user_input)
        test._add_node(SearchNode(SearchNodeHelper.alphabet))

        #add more values, and cheat so as to make them something forbidden
        for bad_val in forbidden_seq:
            curr_node = SearchNode(SearchNodeHelper.alphabet)
            curr_node._options[0] = bad_val  #torque the node's innards
            test._add_node(curr_node)
        #next bad_val

        real_result = test._check_forbidden_seqs()
        self.assertEquals(real_result, True)
Ejemplo n.º 13
0
    def test_get_nmer_len1(self):
        """get_nmer should return correct result for nmer 1 on full stack"""

        test_path = SearchPath(SearchPathHelper.alphabets, \
                SearchPathHelper.standard_forbid_seq)
        test_node = SearchNode(SearchNodeHelper.alphabet)
        test_path._add_node(test_node)
        correct_result = test_node.Value
        real_result = test_path._get_nmer(1)
        self.assertEquals(real_result, correct_result)
Ejemplo n.º 14
0
    def test_check_forbidden_seqs_none(self):
        """Should return False if path includes no forbidden seqs"""
        
        #a seq that isn't in the standard fixed forbidden lib
        allowed_seq = ["C", "U", "A", "T"]        
        
        test = SearchPath(SearchPathHelper.alphabets, \
                SearchPathHelper.standard_forbid_seq)
        test._add_node(SearchNode(SearchNodeHelper.alphabet))

        #add more values, and cheat so as to make them something known
        for known_val in allowed_seq:
            curr_node = SearchNode(SearchNodeHelper.alphabet)
            curr_node._options[0] = known_val #torque the node's innards
            test._add_node(curr_node)
        #next bad_val
        
        real_result = test._check_forbidden_seqs()
        self.assertEquals(real_result, False)            
Ejemplo n.º 15
0
 def test_check_forbidden_seqs_fixed(self):
     """Should return True if path includes a fixed forbidden seq"""
     
     forbidden_seq = ["G", "U", "A"]     
     user_input = ["".join(forbidden_seq)]
     user_input.extend(SearchPathHelper.standard_forbid_seq)
     
     test = SearchPath(SearchPathHelper.alphabets, user_input)
     test._add_node(SearchNode(SearchNodeHelper.alphabet))
     
     #add more values, and cheat so as to make them something forbidden
     for bad_val in forbidden_seq:
         curr_node = SearchNode(SearchNodeHelper.alphabet)
         curr_node._options[0] = bad_val #torque the node's innards
         test._add_node(curr_node)
     #next bad_val
     
     real_result = test._check_forbidden_seqs()
     self.assertEquals(real_result, True)            
Ejemplo n.º 16
0
    def test_get_nmer_tooLong(self):
        """get_nmer should return None for n > length of stack"""

        test_path = SearchPath(SearchPathHelper.alphabets, \
                SearchPathHelper.standard_forbid_seq)
        test_node = SearchNode(SearchNodeHelper.alphabet)
        test_path._add_node(test_node)

        #stack is 1 long.  Ask for a 2 mer
        real_result = test_path._get_nmer(2)
        self.assertEquals(real_result, None)
Ejemplo n.º 17
0
    def _fill_path(self, num_nodes, node_vals=[]):
        """create a searchpath and add searchnodes; return path"""

        test = SearchPath(SearchPathHelper.alphabets, \
                SearchPathHelper.standard_forbid_seq)
        for i in xrange(num_nodes):
            curr_node = SearchNode(SearchNodeHelper.alphabet)
            node_vals.append(curr_node.Value)
            test._add_node(curr_node)
        #next i

        return test
Ejemplo n.º 18
0
    def test_get_nmer(self):
        """get_nmer should return correct nmer for n <= length of stack"""

        node_values = []
        n = 4

        test_path = SearchPath(SearchPathHelper.alphabets, \
                SearchPathHelper.standard_forbid_seq)

        for i in xrange(n + 1):
            curr_node = SearchNode(SearchNodeHelper.alphabet)
            test_path._add_node(curr_node)
            node_values.append(curr_node.Value)
        #next

        #get a nmer, and get the last n values that were put on stack;
        #should be the same
        real_result = test_path._get_nmer(n)
        correct_result = "".join(node_values[-n:])
        self.assertEquals(real_result, correct_result)