[m-rev.] diff: test style
Zoltan Somogyi
zs at csse.unimelb.edu.au
Thu Dec 13 19:37:59 AEDT 2007
tests/hard_coded/construct_bug.m:
tests/hard_coded/construct_bug_submodule.m:
tests/hard_coded/typeclasses/complicated_constraint.m:
Make these tests conform to our style conventions. The old style made
the code quite hard to read.
cvs diff: Diffing tests/hard_coded
Index: tests/hard_coded/construct_bug.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/construct_bug.m,v
retrieving revision 1.1
diff -u -b -r1.1 construct_bug.m
--- tests/hard_coded/construct_bug.m 16 Feb 2004 02:28:09 -0000 1.1
+++ tests/hard_coded/construct_bug.m 13 Dec 2007 05:29:11 -0000
@@ -1,3 +1,4 @@
+% vim: ft=mercury ts=4 sw=4 et
% This is a regression test for a bug in construct.get_functor/5,
% where it was not handling equivalence types properly.
@@ -11,9 +12,14 @@
:- implementation.
-:- import_module list, int, std_util, require, string.
:- import_module construct_bug_submodule.
+:- import_module int.
+:- import_module list.
+:- import_module require.
+:- import_module std_util.
+:- import_module string.
+
main(!IO) :-
FileName = "temp.term",
@@ -27,50 +33,51 @@
count(["B","B3"], !S),
count(["C"], !S),
count(["C","C1"], !S)
- ), construct_bug_submodule__init, Map),
+ ), construct_bug_submodule.init, Map),
- io__open_binary_output(FileName, Result, !IO),
- (
- if (Result = ok(Temp___ORDIE___Out___OutStream) )
- then (OutStream = Temp___ORDIE___Out___OutStream, true)
- else error( "Failed to write to '"++FileName++"'.")
+ io.open_binary_output(FileName, Result, !IO),
+ ( Result = ok(Temp_ORDIE_Out_OutStream) ->
+ OutStream = Temp_ORDIE_Out_OutStream
+ ;
+ error( "Failed to write to '" ++ FileName ++ "'.")
),
- io__write_binary(OutStream, Map, !IO),
+ io.write_binary(OutStream, Map, !IO),
close_binary_output(OutStream, !IO),
- io__write_string("Saved the map to file: "++FileName++"\n", !IO),
+ io.write_string("Saved the map to file: " ++ FileName ++ "\n", !IO),
- io__open_binary_input(FileName, Result2, !IO),
- (
- if (Result2 = ok(Temp___ORDIE___Out___InStream) )
- then (InStream = Temp___ORDIE___Out___InStream, true)
- else error( "Failed to open '"++FileName++"'.")
+ io.open_binary_input(FileName, Result2, !IO),
+ ( Result2 = ok(Temp_ORDIE_Out_InStream) ->
+ InStream = Temp_ORDIE_Out_InStream
+ ;
+ error( "Failed to open '" ++ FileName ++ "'.")
),
- io__read_binary(InStream, MayDataTerm, !IO),
- io__close_binary_input(InStream, !IO),
+ io.read_binary(InStream, MayDataTerm, !IO),
+ io.close_binary_input(InStream, !IO),
(
- MayDataTerm = ok(ReadMap`with_type`stat)
- ; MayDataTerm = eof,
- error("Unexpected end of file: '"++FileName++"'.")
- ; MayDataTerm = error(E),
- error("Error reading term from: '"++FileName++"': "
- ++io__error_message(E)++".")
+ MayDataTerm = ok(ReadMap `with_type` stat)
+ ;
+ MayDataTerm = eof,
+ error("Unexpected end of file: '" ++ FileName ++ "'.")
+ ;
+ MayDataTerm = error(E),
+ error("Error reading term from: '" ++ FileName ++ "': "
+ ++ io.error_message(E) ++ ".")
),
- io__write_string("Loaded the map from file: "++FileName++"\n", !IO),
+ io.write_string("Loaded the map from file: " ++ FileName ++ "\n", !IO),
- (
- if Map = ReadMap
- then
- io__write_string("The representations are identical.\n", !IO)
- else
- io__write_string("The representations are different.\n", !IO)
+ ( Map = ReadMap ->
+ io.write_string("The representations are identical.\n", !IO)
+ ;
+ io.write_string("The representations are different.\n", !IO)
),
- io__remove_file(FileName, RmResult, !IO),
- ( RmResult = ok
- ; RmResult = error(E2),
- error("Error deleting file '"++FileName++"': "
- ++io__error_message(E2)++".")
+ io.remove_file(FileName, RmResult, !IO),
+ (
+ RmResult = ok
+ ;
+ RmResult = error(E2),
+ error("Error deleting file '" ++ FileName ++ "': "
+ ++ io.error_message(E2) ++ ".")
).
-
Index: tests/hard_coded/construct_bug_submodule.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/construct_bug_submodule.m,v
retrieving revision 1.2
diff -u -b -r1.2 construct_bug_submodule.m
--- tests/hard_coded/construct_bug_submodule.m 29 Mar 2006 08:07:59 -0000 1.2
+++ tests/hard_coded/construct_bug_submodule.m 13 Dec 2007 05:29:11 -0000
@@ -1,4 +1,7 @@
+% vim: ft=mercury ts=4 sw=4 et
+%
% This is part of the construct_bug test case.
+
:- module construct_bug_submodule.
:- interface.
@@ -39,7 +42,6 @@
:- func to_string(stat::in) = (string::out) is det.
:- func subs_to_string(stat::in) = (string::out) is det.
-
%% Other useful predicates for evaluating something
:- func minavgmax_string(list(int)::in) = (string::out) is det.
@@ -52,13 +54,13 @@
:- type stat == bag(list(string)).
-init = bag__init.
-blank = construct_bug_submodule__init.
+init = bag.init.
+blank = construct_bug_submodule.init.
count(Elem, InStat, OutStat) :-
- bag__insert(InStat, Elem, OutStat).
+ bag.insert(InStat, Elem, OutStat).
count(Count, Elem, InStat, OutStat) :-
- bag__insert_list(InStat, list__duplicate(Count, Elem), OutStat).
+ bag.insert_list(InStat, list.duplicate(Count, Elem), OutStat).
count_more(Elem, Count, InStat, OutStat) :-
count(Count, Elem, InStat, OutStat).
@@ -69,8 +71,8 @@
count(Count, Elem, InStat) = OutStat :-
count(Count, Elem, InStat, OutStat).
-union(A, B) = bag__union(A, B).
-to_assoc_list(Stat) = bag__to_assoc_list(Stat).
+union(A, B) = bag.union(A, B).
+to_assoc_list(Stat) = bag.to_assoc_list(Stat).
to_string(Stat) =
"% Base Counts:\n"
@@ -81,51 +83,50 @@
plain_to_string(calc_subtotals(Stat)).
plain_to_string(Stat) = Out :-
- Counts = bag__to_assoc_list(Stat),
- list__sort(comparator(Stat,0), Counts, CountsS),
- list__map(
- (pred((Name-Count)::in, Line::out) is det :-
- Line = string__int_to_string(Count)++"\t"++join_list("-", Name)
+ Counts = bag.to_assoc_list(Stat),
+ list.sort(comparator(Stat,0), Counts, CountsS),
+ list.map(
+ (pred((Name - Count)::in, Line::out) is det :-
+ Line = string.int_to_string(Count) ++ "\t" ++ join_list("-", Name)
), CountsS, Lines),
- Out = join_list("\n", Lines)++"\n"
- .
+ Out = join_list("\n", Lines) ++ "\n".
-:- pred comparator(stat, int, pair(statkey, int), pair(statkey, int), comparison_result).
-:- mode comparator(in, in, in, in, out) is det.
+:- pred comparator(stat::in, int::in,
+ pair(statkey, int)::in, pair(statkey, int)::in, comparison_result::out)
+ is det.
comparator(Stats, Level, (ADescr-ANum), (BDescr-BNum), Out) :-
- if take(Level, ADescr, ALevel)
- then
- (
- if take(Level, BDescr, BLevel)
- then
- (
- if count_value(Stats, ALevel) < count_value(Stats, BLevel)
- then Out = (>)
- else
- if count_value(Stats, ALevel) > count_value(Stats, BLevel)
- then Out = (<)
- else
+ ( take(Level, ADescr, ALevel) ->
+ ( take(Level, BDescr, BLevel) ->
+ ( count_value(Stats, ALevel) < count_value(Stats, BLevel) ->
+ Out = (>)
+ ; count_value(Stats, ALevel) > count_value(Stats, BLevel) ->
+ Out = (<)
+ ;
% same value
- if ALevel = BLevel
- then comparator(Stats, Level+1, (ADescr-ANum), (BDescr-BNum), Out)
- else
- if compare((<), ALevel, BLevel)
- then Out = (>)
- else Out = (<)
+ ( ALevel = BLevel ->
+ comparator(Stats, Level+1, (ADescr-ANum), (BDescr-BNum),
+ Out)
+ ; compare((<), ALevel, BLevel) ->
+ Out = (>)
+ ;
+ Out = (<)
)
- else
+ )
+ ;
Out = (>)
)
- else
- if take(Level, BDescr, _BLevel)
- then Out = (<)
- else Out = (=).
+ ; take(Level, BDescr, _BLevel) ->
+ Out = (<)
+ ;
+ Out = (=)
+ ).
:- func calc_subtotals(stat::in) = (stat::out) is det.
+
calc_subtotals(Stat) = OutStat :-
- Counts = bag__to_assoc_list(Stat),
- list__foldl(
+ Counts = bag.to_assoc_list(Stat),
+ list.foldl(
(pred((Name - Count)::in, InBag::in, OutBag::out) is det :-
aggregate(substarts(Name), count(Count), InBag, OutBag)
), Counts, Stat, OutStat).
@@ -133,7 +134,7 @@
/*
** buggy pprint, do not use.
to_string(Stat) = Str :-
- Str = pprint__to_string(150, construct_bug_submodule__to_doc(Stat)).
+ Str = pprint.to_string(150, construct_bug_submodule.to_doc(Stat)).
to_doc(Stat) =
text("% Base Counts:\n")
@@ -146,7 +147,7 @@
:- func subtotals_to_doc(stat::in) = (doc::out) is det.
plain_to_doc(Stat) = Out :-
- Counts = bag__to_assoc_list(Stat),
+ Counts = bag.to_assoc_list(Stat),
Out =
% text("% Statistiky") `</>`
separated(
@@ -157,8 +158,8 @@
`<>` line.
subtotals_to_doc(Stat) = Out :-
- Counts = bag__to_assoc_list(Stat),
- list__foldl(
+ Counts = bag.to_assoc_list(Stat),
+ list.foldl(
(pred((Name - Count)::in, InBag::in, OutBag::out) is det :-
aggregate(substarts(Name), count(Count), InBag, OutBag)
), Counts, Stat, Subtotals),
@@ -168,22 +169,25 @@
substarts([], []).
substarts([_LastElem], []).
-substarts([Elem1, Elem2|Rest], Out) :-
+substarts([Elem1, Elem2 | Rest], Out) :-
+ (
Out = []
;
- substarts([Elem2|Rest], TOut),
- Out = [Elem1|TOut].
-
+ substarts([Elem2 | Rest], TOut),
+ Out = [Elem1 | TOut]
+ ).
:- import_module float.
-minavgmax_string(List) = int_to_string(length(List))++":"++Min++"/"++Avg++"/"++Max :-
+minavgmax_string(List) = Str :-
+ (
List = [],
Min = "-", Avg = "-", Max = "-"
;
- List = [H|Tail],
- list__foldl3(
- (pred(N::in, MinSoFar::in, NewMin::out, MaxSoFar::in, NewMax::out, SumSoFar::in, NewSum::out) is det:-
+ List = [H | Tail],
+ list.foldl3(
+ (pred(N::in, MinSoFar::in, NewMin::out, MaxSoFar::in, NewMax::out,
+ SumSoFar::in, NewSum::out) is det:-
NewSum = SumSoFar + N,
NewMin = (if N < MinSoFar then N else MinSoFar),
NewMax = (if N > MaxSoFar then N else MaxSoFar)
@@ -192,6 +196,7 @@
Max = int_to_string(MaxN),
Prec = float(10),
Avg = float_to_string(float(round_to_int(
- (float(SumN)/float(length(List)))*Prec
- ))/Prec)
- .
+ (float(SumN) / float(length(List))) * Prec)) / Prec)
+ ),
+ Str = int_to_string(length(List)) ++ ":"
+ ++ Min ++ "/" ++ Avg ++ "/" ++ Max.
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
Index: tests/hard_coded/typeclasses/complicated_constraint.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/typeclasses/complicated_constraint.m,v
retrieving revision 1.2
diff -u -b -r1.2 complicated_constraint.m
--- tests/hard_coded/typeclasses/complicated_constraint.m 1 Dec 2003 15:56:09 -0000 1.2
+++ tests/hard_coded/typeclasses/complicated_constraint.m 13 Dec 2007 05:29:24 -0000
@@ -1,9 +1,13 @@
+% vim: ft=mercury ts=4 sw=4 et
+
:- module complicated_constraint.
+
:- interface.
-:- import_module io, list.
+:- import_module io.
+:- import_module list.
:- typeclass printable(A) where [
- pred p(A::in, io__state::di, io__state::uo) is det
+ pred p(A::in, io.state::di, io.state::uo) is det
].
:- typeclass foo(A) <= printable(A) where [
pred b(A::in) is semidet
@@ -14,13 +18,13 @@
:- instance printable(list(T)) <= foo(T).
:- instance foo(list(T)) <= foo(T).
-:- pred main(io__state::di, io__state::uo) is det.
+:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int.
:- instance printable(int) where [
- pred(p/3) is io__write_int
+ pred(p/3) is io.write_int
].
:- instance foo(int) where [
@@ -35,29 +39,32 @@
:- pred p_list(list(T), state, state) <= printable(T).
:- mode p_list(in, di, uo) is det.
-p_list(Xs) --> list__foldl(p, Xs).
+
+p_list(Xs) -->
+ list.foldl(p, Xs).
main -->
p(42),
- io__write_string("\n"),
+ io.write_string("\n"),
p_list([1,2,3]),
- io__write_string("\n"),
+ io.write_string("\n"),
p([1,2,3]),
- io__write_string("\n"),
+ io.write_string("\n"),
blah(101),
- io__write_string("\n").
-
+ io.write_string("\n").
:- pred list_b(list(T)::in) is semidet <= foo(T).
+
list_b(List) :-
- list__map((pred(A::in, A::out) is semidet :- b(A)), List, _).
+ list.map((pred(A::in, A::out) is semidet :- b(A)), List, _).
:- pred foo_b(int::in) is semidet.
+
foo_b(1).
% This tests complicated constraints of the form `foo(bar(T))'.
-:- pred blah(T, io__state, io__state) <= (foo(list(T)), printable(list(T))).
+:- pred blah(T, io, io) <= (foo(list(T)), printable(list(T))).
:- mode blah(in, di, uo) is det.
blah(X) -->
@@ -69,5 +76,4 @@
;
io__write_string("false\n")
),
-
p([X]).
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list