Advertisement
Guest User

Using Prolog to Generate Test Data

a guest
Aug 6th, 2012
123
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.54 KB | None
  1. #!/usr/bin/swipl -q -t run -f
  2.  
  3. subset([], []).
  4. subset([E | Tail], [E | NTail]) :-
  5.    subset(Tail, NTail).
  6. subset([_ | Tail], NTail) :-
  7.    subset(Tail, NTail).
  8.  
  9. validate(0, 1).
  10. validate(X, Max) :-
  11.    Max > 1,
  12.    Y is Max - 1,
  13.    (
  14.       X = Y
  15.    ;
  16.       validate(X, Y)
  17.    ).
  18.  
  19. generate(L) :-
  20.    validate(N, 5),
  21.    length(L, N).
  22.  
  23. main :-
  24.    generate(L),
  25.    subset(['A', 'A#', 'B', 'C', 'C#', 'D',
  26.            'D#', 'E', 'F', 'F#', 'G', 'G#'], L),
  27.    format("~q~n", [L]),
  28.    fail.
  29.  
  30. main :-
  31.    true.
  32.  
  33. run :-
  34.    main, halt.
Advertisement
RAW Paste Data Copied
Advertisement