-- test_combinations.adb instantiations of generic procedure -- n is for n things n! / ((n-m)! m!) combinations -- m is for m at a time -- Vn must be the n items, unchanged by combinations -- Vm must be of size m items, the returned combination each call -- First must be true the first call, then set to false internally -- Last is false if more combinations to come. -- Last is True for the final combination with Ada.Text_Io; use Ada.Text_Io; with Combinations; -- generic procedure Test_Combinations is type Vector_Type is array(Integer range <>) of Integer; Vn : Vector_Type(1..4) := (1, 2, 3, 4); Vm : Vector_Type(1..2); type Long_Float_Type is array(Integer range <>) of Long_Float; Vnf : Long_Float_Type(1..6) := (1.0, 2.0, 3.0, 4.0, 5.0, 6.0); Vmf : Long_Float_Type(1..3); type Character_Type is array(Integer range <>) of Character; Vnc : Character_Type(1..6) := ('a', 'b', 'c', 'd', 'e', 'f'); Vmc : Character_Type(1..7); First, Last : Boolean; N, M, Cnt : Integer := 0; -- max_size, item type, vector type package My_Combinations is new Combinations(4, Integer, Vector_Type); package Combinationsf is new Combinations(6, Long_Float, Long_Float_Type); package Combinationsc is new Combinations(6, Character, Character_Type); begin Put_Line("test_combinations.adb running"); First := True; Last := False; N := 4; M := 2; Cnt := 0; Put_Line("n="&Integer'Image(N)&", m="&Integer'Image(M)&", Vn= 1, 2, 3, 4"); while not Last loop My_Combinations.comb(N, M, Vn, Vm, First, Last); Cnt := Cnt +1; Put_Line(Integer'Image(Cnt)&" Vm "&integer'Image(Vm(1))& Integer'Image(Vm(2))&" First="&Boolean'Image(First)& " Last ="&Boolean'Image(Last)); end loop; New_Line; First := True; Last := False; N := 6; M := 3; Cnt := 0; Put_Line("n="&Integer'Image(N)&", m="&Integer'Image(M)& ", Vnf= 1.0, 2.0, 3.0, 4.0, 5.0, 6.0"); while not Last loop Combinationsf.comb(N, M, Vnf, Vmf, First, Last); Cnt := Cnt +1; Put_Line(Integer'Image(Cnt)&" Vmf "&Long_Float'Image(Vmf(1))& Long_Float'Image(Vmf(2))&Long_Float'Image(Vmf(3))); end loop; New_Line; N := 6; for M in 0..7 loop -- last case error message First := True; Last := False; Cnt := 0; Put_Line("n="&Integer'Image(N)&", m="&Integer'Image(M)& ", Vnc= a b c d e f "); while not Last loop Combinationsc.comb(N, M, Vnc, Vmc, First, Last); Cnt := Cnt +1; Put(Integer'Image(Cnt)&" Vmc "); for I in 1..M loop Put(" "&Vmc(i)); end loop; New_Line; end loop; end loop; New_Line; Put_Line("test_combinations.adb ends"); end Test_Combinations;