test_Permutation.praat 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # test_Permutation.praat
  2. # djmw 20050710, 20070820, 20100525, 20100819, 20110418
  3. appendInfoLine: "test_Permutation.praat"
  4. @test_600_12
  5. @rotate
  6. @sequence
  7. @swap
  8. @invertp
  9. @multiply
  10. @jump
  11. appendInfoLine: "test_Permutation OK"
  12. procedure multiply:
  13. appendInfo: tab$, "Multiply"
  14. .numberOfPermutations = 8
  15. .numberOfElements = 5
  16. for .i to .numberOfPermutations / 2
  17. .p [2*.i -1] = Create Permutation: "p", .numberOfElements, "no"
  18. .p [2*.i] = Invert
  19. endfor
  20. selectObject: .p [1]
  21. for .i from 2 to .numberOfPermutations
  22. plusObject: .p [.i]
  23. endfor
  24. .p [.numberOfPermutations + 1] = Multiply
  25. for .j to .numberOfElements
  26. .val = Get value: .j
  27. assert .val = .j; p ['.j']='.val'
  28. appendInfo: "."
  29. endfor
  30. for .i to .numberOfPermutations + 1
  31. removeObject: .p [.i]
  32. endfor
  33. appendInfoLine: ".o.k."
  34. endproc
  35. procedure rotate
  36. appendInfoLine: tab$, "Rotate"
  37. for .i to 20
  38. .p = Create Permutation: "test", .i, "yes"
  39. appendInfo: tab$, .i
  40. for .k to .i
  41. selectObject: .p
  42. .pk = Rotate: 0, 0, .k
  43. .pkk = Get value: .k+1
  44. if .pkk > 0
  45. assert .pkk = 1 ; i='.i', k='.k'
  46. endif
  47. .pki = Rotate: 0, 0, -.k
  48. for .l to .k
  49. .pkil = Get value: .l
  50. assert .pkil = .l
  51. endfor
  52. removeObject: .pk, .pki
  53. appendInfo: "."
  54. endfor
  55. appendInfoLine: " o.k."
  56. removeObject: .p
  57. endfor
  58. endproc
  59. procedure invertp
  60. appendInfo: tab$, "Invert"
  61. for .i to 20
  62. .p = Create Permutation: "test", .i, "yes"
  63. .pin = Invert
  64. plusObject: .p
  65. .pm = Multiply
  66. for .k to .i
  67. .pmk = Get value: .k
  68. assert .pmk = .k ; i='.i', k='.k'
  69. endfor
  70. appendInfo: "."
  71. removeObject: .pin, .p, .pm
  72. endfor
  73. appendInfoLine: "o.k."
  74. endproc
  75. procedure test_600_12
  76. appendInfo: tab$, "test_600_12"
  77. .p = Create Permutation: "600", 600, "yes"
  78. .pin = Interleave: 0, 0, 12, 1
  79. .pininv = Invert
  80. plusObject: .pin
  81. .pm = Multiply
  82. for .l to 600
  83. .pkil = Get value: .l
  84. assert .pkil = .l; l='.l'
  85. endfor
  86. removeObject: .pin, .pininv, .p, .pm
  87. appendInfoLine: "o.k."
  88. endproc
  89. procedure sequence
  90. appendInfo: tab$, "Sequences"
  91. .n = 4
  92. .np = 4*3*2 - 1
  93. p = Create Permutation: "ps", .n, "yes"
  94. for .j to .np
  95. for .i to .j
  96. Next
  97. endfor
  98. for .i to .j
  99. Previous
  100. endfor
  101. for .i to .n
  102. .val = Get value: .i
  103. assert .val = .i
  104. endfor
  105. appendInfo: "."
  106. endfor
  107. removeObject: p
  108. appendInfoLine: "o.k."
  109. endproc
  110. procedure swap
  111. appendInfo: tab$, "Swap positions"
  112. .p = Create Permutation: "id", 10, "yes"
  113. for .i to 10
  114. for .j to 10
  115. selectObject: .p
  116. .ps = Copy: "swap"
  117. Swap positions: .i, .j
  118. for .k to 10
  119. selectObject: .p
  120. .pk = Get value: .k
  121. selectObject: .ps
  122. .psk = Get value: .k
  123. if .k <> .i and .k <> .j
  124. assert .pk = .psk
  125. endif
  126. endfor
  127. removeObject: .ps
  128. appendInfo: "."
  129. endfor
  130. endfor
  131. removeObject: .p
  132. appendInfoLine: "o.k."
  133. endproc
  134. procedure jump
  135. appendInfo: tab$, "Jump"
  136. .p1 = Create Permutation: "id", 10, "yes"
  137. Jump: 3, 1
  138. for .i to 10
  139. .p [.i] = Get value: .i
  140. endfor
  141. assert .p [1] = 1
  142. assert .p [2] = 4
  143. assert .p [3] = 7
  144. assert .p [4] = 10
  145. assert .p [5] = 2
  146. assert .p [6] = 5
  147. assert .p [7] = 8
  148. assert .p [8] = 3
  149. assert .p [9] = 6
  150. assert .p [10] = 9
  151. appendInfo: "."
  152. .p2 = Create Permutation: "id", 10, "yes"
  153. Jump: 3, 2
  154. for .i to 10
  155. .p [.i] = Get value: .i
  156. endfor
  157. assert .p [1] = 2
  158. assert .p [2] = 5
  159. assert .p [3] = 8
  160. assert .p [4] = 3
  161. assert .p [5] = 6
  162. assert .p [6] = 9
  163. assert .p [7] = 1
  164. assert .p [8] = 4
  165. assert .p [9] = 7
  166. assert .p [10] = 10
  167. removeObject: .p1, .p2
  168. appendInfoLine: ".o.k."
  169. endproc