|
@@ -0,0 +1,83 @@
|
|
|
|
+:-module(test2,
|
|
|
|
+ [limit_for_1_month/4,
|
|
|
|
+ limit_for_1_month2/4,
|
|
|
|
+ test/0]).
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+
|
|
|
|
+2. Описать месячный лимит на транзакции по Грузии, используя Пролог,
|
|
|
|
+ если сумма - 10 000 теньге, количество - 15 транзакций.
|
|
|
|
+ Описание вида: limit_for_1_month(Country, LimitSum, LimitCount, LimitCurrency).
|
|
|
|
+
|
|
|
|
+*/
|
|
|
|
+
|
|
|
|
+% в Грузії - ларі, теньге в Казахстані
|
|
|
|
+
|
|
|
|
+% limit_for_1_month(Country, LimitSum, LimitCount, LimitCurrency). % сума ліміту не в копійках (ларі, не тетрі); ліміт включно
|
|
|
|
+limit_for_1_month(ge, LimitSum, LimitCount, gel) :-
|
|
|
|
+ integer(LimitSum), LimitSum > 0, LimitSum =< 10_000,
|
|
|
|
+ integer(LimitCount), LimitCount > 0, LimitCount =< 15.
|
|
|
|
+
|
|
|
|
+% limit_for_1_month2(Country, LimitSum, LimitCount, LimitCurrency). % сума ліміту в копійках (100 тетрі = 1 ларі); ліміт включно
|
|
|
|
+limit_for_1_month2(ge, LimitSum, LimitCount, gel) :-
|
|
|
|
+ integer(LimitSum), LimitSum > 0, LimitSum =< 10_000_00,
|
|
|
|
+ integer(LimitCount), LimitCount > 0, LimitCount =< 15.
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+test() :-
|
|
|
|
+ Values1 = [[ge, 9_999, 5, gel], [ge, 10_000, 10, gel], [ge, 10_001, 15, gel],
|
|
|
|
+ [ge, 9_999, 15, gel], [ge, 10_000, 20, gel], [ge, -1, 2, gel], [ge, 5, 0, gel]],
|
|
|
|
+ test1(Values1), % testing limit_for_1_month/4
|
|
|
|
+ nl,
|
|
|
|
+ Values2 = [[ge, 9_999_99, 5, gel], [ge, 10_000_00, 10, gel], [ge, 10_000_01, 15, gel],
|
|
|
|
+ [ge, 9_999_99, 15, gel], [ge, 10_000_00, 20, gel], [ge, -1, 2, gel], [ge, 5, 0, gel]],
|
|
|
|
+ test1_2(Values2). % testing limit_for_1_month2/4
|
|
|
|
+
|
|
|
|
+test1([]) :- true.
|
|
|
|
+test1([V|T]) :-
|
|
|
|
+ [C, S, N, C2] = V,
|
|
|
|
+ limit_for_1_month(C, S, N, C2),
|
|
|
|
+ format("~w -> ~w~n", [limit_for_1_month(C, S, N, C2), true]),
|
|
|
|
+ test1(T);
|
|
|
|
+ % ліміт false
|
|
|
|
+ format("limit_for_1_month(~w,~w,~w,~w) -> false~n", V),
|
|
|
|
+ test1(T).
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+test1_2(L) :-
|
|
|
|
+ forall(member(V, L),
|
|
|
|
+ ([C, S, N, C2] = V,
|
|
|
|
+ limit_for_1_month2(C, S, N, C2),
|
|
|
|
+ format("~w -> ~w~n", [limit_for_1_month2(C, S, N, C2), true]);
|
|
|
|
+ % ліміт false
|
|
|
|
+ format("limit_for_1_month2(~w,~w,~w,~w) -> false~n", V)
|
|
|
|
+ )).
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+
|
|
|
|
+$ prolog
|
|
|
|
+
|
|
|
|
+?- consult(test2).
|
|
|
|
+true.
|
|
|
|
+
|
|
|
|
+?- test().
|
|
|
|
+limit_for_1_month(ge,9999,5,gel) -> true
|
|
|
|
+limit_for_1_month(ge,10000,10,gel) -> true
|
|
|
|
+limit_for_1_month(ge,10001,15,gel) -> false
|
|
|
|
+limit_for_1_month(ge,9999,15,gel) -> true
|
|
|
|
+limit_for_1_month(ge,10000,20,gel) -> false
|
|
|
|
+limit_for_1_month(ge,-1,2,gel) -> false
|
|
|
|
+limit_for_1_month(ge,5,0,gel) -> false
|
|
|
|
+
|
|
|
|
+limit_for_1_month2(ge,999999,5,gel) -> true
|
|
|
|
+limit_for_1_month2(ge,1000000,10,gel) -> true
|
|
|
|
+limit_for_1_month2(ge,1000001,15,gel) -> false
|
|
|
|
+limit_for_1_month2(ge,999999,15,gel) -> true
|
|
|
|
+limit_for_1_month2(ge,1000000,20,gel) -> false
|
|
|
|
+limit_for_1_month2(ge,-1,2,gel) -> false
|
|
|
|
+limit_for_1_month2(ge,5,0,gel) -> false
|
|
|
|
+true
|
|
|
|
+
|
|
|
|
+*/
|
|
|
|
+
|