Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Test-a-function/Ada/test-a-function-1.ada
Normal file
28
Task/Test-a-function/Ada/test-a-function-1.ada
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Test_Function is
|
||||
|
||||
function Palindrome (Text : String) return Boolean is
|
||||
begin
|
||||
for Offset in 0 .. Text'Length / 2 - 1 loop
|
||||
if Text (Text'First + Offset) /= Text (Text'Last - Offset) then
|
||||
return False;
|
||||
end if;
|
||||
end loop;
|
||||
return True;
|
||||
end Palindrome;
|
||||
|
||||
str1 : String := "racecar";
|
||||
str2 : String := "wombat";
|
||||
|
||||
begin
|
||||
begin
|
||||
pragma Assert(False); -- raises an exception if assertions are switched on
|
||||
Ada.Text_IO.Put_Line("Skipping the test! Please compile with assertions switched on!");
|
||||
exception
|
||||
when others => -- assertions are switched on -- perform the tests
|
||||
pragma Assert (Palindrome (str1) = True, "Assertion on str1 failed");
|
||||
pragma Assert (Palindrome (str2) = False, "Assertion on str2 failed");
|
||||
Ada.Text_IO.Put_Line("Test Passed!");
|
||||
end;
|
||||
end Test_Function;
|
||||
5
Task/Test-a-function/Ada/test-a-function-2.ada
Normal file
5
Task/Test-a-function/Ada/test-a-function-2.ada
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
function Palindrome (Text : String) return Boolean
|
||||
with Post => Palindrome'Result =
|
||||
(Text'Length < 2 or else
|
||||
((Text(Text'First) = Text(Text'Last)) and then
|
||||
Palindrome(Text(Text'First+1 .. Text'Last-1))));
|
||||
Loading…
Add table
Add a link
Reference in a new issue