<s> from unittest import TestCase <EOL> from chatterbot . adapters . logic import ClosestMatchAdapter <EOL> from chatterbot . conversation import Statement , Response <EOL> class ClosestMatchAdapterTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . adapter = ClosestMatchAdapter ( ) <EOL> def test_no_choices ( self ) : <EOL> from chatterbot . adapters . exceptions import EmptyDatasetException <EOL> possible_choices = [ ] <EOL> statement = Statement ( "<STR_LIT>" ) <EOL> with self . assertRaises ( EmptyDatasetException ) : <EOL> self . adapter . get ( statement , possible_choices ) <EOL> def test_get_closest_statement ( self ) : <EOL> """<STR_LIT>""" <EOL> possible_choices = [ <EOL> Statement ( "<STR_LIT>" , in_response_to = [ Response ( "<STR_LIT>" ) ] ) , <EOL> Statement ( "<STR_LIT>" , in_response_to = [ Response ( "<STR_LIT>" ) ] ) , <EOL> Statement ( "<STR_LIT>" , in_response_to = [ Response ( "<STR_LIT>" ) ] ) , <EOL> Statement ( "<STR_LIT>" , in_response_to = [ Response ( "<STR_LIT>" ) ] ) , <EOL> Statement ( "<STR_LIT>" , in_response_to = [ Response ( "<STR_LIT>" ) ] ) , <EOL> Statement ( "<STR_LIT>" , in_response_to = [ Response ( "<STR_LIT>" ) ] ) , <EOL> ] <EOL> statement = Statement ( "<STR_LIT>" ) <EOL> confidence , match = self . adapter . get ( statement , possible_choices ) <EOL> self . assertEqual ( "<STR_LIT>" , match ) <EOL> def test_confidence_exact_match ( self ) : <EOL> possible_choices = [ <EOL> Statement ( "<STR_LIT>" , in_response_to = [ Response ( "<STR_LIT>" ) ] ) <EOL> ] <EOL> statement = Statement ( "<STR_LIT>" ) <EOL> confidence , match = self . adapter . get ( <EOL> statement , possible_choices <EOL> ) <EOL> self . assertEqual ( confidence , <NUM_LIT:1> ) <EOL> def test_confidence_half_match ( self ) : <EOL> possible_choices = [ <EOL> Statement ( "<STR_LIT>" , in_response_to = [ Response ( "<STR_LIT>" ) ] ) <EOL> ] <EOL> statement = Statement ( "<STR_LIT>" ) <EOL> confidence , match = self . adapter . get ( <EOL> statement , possible_choices <EOL> ) <EOL> self . assertEqual ( confidence , <NUM_LIT:0.5> ) <EOL> def test_confidence_no_match ( self ) : <EOL> possible_choices = [ <EOL> Statement ( "<STR_LIT>" , in_response_to = [ Response ( "<STR_LIT>" ) ] ) <EOL> ] <EOL> statement = Statement ( "<STR_LIT>" ) <EOL> confidence , match = self . adapter . get ( <EOL> statement , possible_choices <EOL> ) <EOL> self . assertEqual ( confidence , <NUM_LIT:0> ) </s>
