Skip to content

Commit

Permalink
more tests and fixes for inserting a space on empty groups
Browse files Browse the repository at this point in the history
  • Loading branch information
zmughal committed Nov 23, 2011
1 parent 813ae1f commit 2416e46
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 0 additions & 3 deletions future_test

This file was deleted.

10 changes: 7 additions & 3 deletions numberals.pl
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,19 @@
number_to_name_group([H,T,O|NumNext], Name, Group) :-
Group >= 0,
( [H, T, O] = [0, 0, 0] -> Group_Name = ""; power_name(Group, Group_Name) ),
(Group_Name \= "" -> Space = " "; Space = ""),
number_to_name_prefix([H,T,O], Group_Prefix),
GroupNext is Group - 3,
number_to_name_group(NumNext, NameNext, GroupNext),
append([Group_Prefix, Space, Group_Name, NameNext], Name).
(Group_Name == "" -> Space = ""; Space = " "),
add_space_nextname(NameNext, NameNextS),
append([Group_Prefix, Space, Group_Name, NameNextS], Name).
number_to_name_group([], "", _).
add_space_nextname("", "").
add_space_nextname([32|NextName], [32|NextName]).
add_space_nextname([First|NextName], [32,First|NextName]) :- First \= 32.
% }}}
% hundred helpers {{{
number_to_name_prefix([ 0, 0, 0], "").
number_to_name_prefix([ 0, 0, 0], "") :- !.
number_to_name_prefix([ 0, 0, Ones], Name) :- Ones \= 0, number_to_name( [Ones], Name).
number_to_name_prefix([ 0, Tens, Ones], Name) :- Tens \= 0, number_to_name( [Tens, Ones], Name).
number_to_name_prefix([Hundreds, Tens, Ones], Name) :- [Hundreds, Tens] \= [0, 0], number_to_name( [Hundreds, Tens, Ones], Name).
Expand Down
9 changes: 8 additions & 1 deletion numberals.plt
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ test(test_both_ways, [nondet, forall( test_both_ways_test(Num, Name) )]) :-
test_to_name_test([1,0,0,0], "one thousand").
test_to_name_test([1,0,0,0,0,0,0], "one million").
test_to_name_test([2,0,0,0,0,0,0], "two million").
test_to_name_test([2,0,0,0,0,0,9], "two million nine").
test_to_name_test([1,0,2,0,0,0,0,0,0], "one hundred and two million").
test_to_name_test([-,1,0,2,0,0,0,0,0,0], "negative one hundred and two million").
test_to_name_test([2,0,0,1,0,0,0,1,0,9], "two billion one million one hundred and nine").
test_to_name_test([2,0,0,1,1,0,0,1,0,9], "two billion one million one hundred thousand one hundred and nine").
test_to_name_test([2,0,0,1,1,2,0,1,0,9], "two billion one million one hundred and twenty thousand one hundred and nine").
test_to_name_test([2,0,0,1,1,2,3,1,0,9], "two billion one million one hundred and twenty-three thousand one hundred and nine").
test_to_name_test([2,0,0,0,0,0,1,0,0,0,1,0,9], "two trillion one million one hundred and nine").
test(test_to_name, [nondet, forall( test_to_name_test(Num, Name) )]) :-
number_to_name(Num, Test_Name), Test_Name = Name.
%number_to_name(Num, Test_Name), Test_Name = Name.
number_to_name(Num, Test_Name), ( Test_Name = Name -> true; write(Test_Name), nl, writef('%s', [Test_Name]), nl, fail).

test_name_fail_test("zero hundred").
test(test_name_fail, [nondet, forall( test_name_fail_test(Name) )]) :-
Expand Down

0 comments on commit 2416e46

Please sign in to comment.