emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/pacmacs b73dd8215c 220/472: Merge branch 'integration-test


From: ELPA Syncer
Subject: [nongnu] elpa/pacmacs b73dd8215c 220/472: Merge branch 'integration-test-replayer-122'. Close #122
Date: Thu, 6 Jan 2022 21:59:26 -0500 (EST)

branch: elpa/pacmacs
commit b73dd8215cd863f1b65f603ccf1291a3b889cf04
Merge: 6a4bf8c87f daca08b8b1
Author: rexim <reximkut@gmail.com>
Commit: rexim <reximkut@gmail.com>

    Merge branch 'integration-test-replayer-122'. Close #122
---
 it-cases/it-case01.el      |  10 ++++
 it-cases/it-case02.el      | 139 +++++++++++++++++++++++++++++++++++++++++++++
 it-cases/it-case03.el      |  63 ++++++++++++++++++++
 pacmacs-board.el           |  14 +++++
 pacmacs-score.el           |   3 +-
 pacmacs-utils.el           |  11 ++--
 pacmacs.el                 |   3 +-
 test/pacmacs-utils-test.el |   5 --
 tools/it-recorder.el       |  39 +++++++++++--
 9 files changed, 271 insertions(+), 16 deletions(-)

diff --git a/it-cases/it-case01.el b/it-cases/it-case01.el
new file mode 100644
index 0000000000..551e6d3271
--- /dev/null
+++ b/it-cases/it-case01.el
@@ -0,0 +1,10 @@
+((pacmacs-down . 7)
+ (pacmacs-right . 10)
+ (pacmacs-down . 14)
+ (pacmacs-right . 17)
+ (pacmacs-down . 21)
+ (pacmacs-right . 26)
+ (pacmacs-up . 30)
+ (pacmacs-left . 32)
+ (pacmacs-up . 34)
+ (pacmacs-left . 37))
diff --git a/it-cases/it-case02.el b/it-cases/it-case02.el
new file mode 100644
index 0000000000..25b1520515
--- /dev/null
+++ b/it-cases/it-case02.el
@@ -0,0 +1,139 @@
+((pacmacs-down . 8)
+ (pacmacs-right . 11)
+ (pacmacs-down . 15)
+ (pacmacs-right . 17)
+ (pacmacs-down . 21)
+ (pacmacs-right . 26)
+ (pacmacs-up . 31)
+ (pacmacs-left . 33)
+ (pacmacs-up . 36)
+ (pacmacs-left . 38)
+ (pacmacs-right . 41)
+ (pacmacs-down . 42)
+ (pacmacs-left . 46)
+ (pacmacs-up . 50)
+ (pacmacs-left . 52)
+ (pacmacs-down . 56)
+ (pacmacs-left . 59)
+ (pacmacs-right . 62)
+ (pacmacs-up . 64)
+ (pacmacs-left . 68)
+ (pacmacs-up . 71)
+ (pacmacs-left . 73)
+ (pacmacs-up . 91)
+ (pacmacs-up . 95)
+ (pacmacs-up . 98)
+ (pacmacs-up . 100)
+ (pacmacs-right . 102)
+ (pacmacs-down . 105)
+ (pacmacs-right . 110)
+ (pacmacs-up . 113)
+ (pacmacs-right . 118)
+ (pacmacs-down . 120)
+ (pacmacs-right . 125)
+ (pacmacs-up . 128)
+ (pacmacs-left . 133)
+ (pacmacs-down . 136)
+ (pacmacs-up . 140)
+ (pacmacs-right . 144)
+ (pacmacs-down . 147)
+ (pacmacs-right . 171)
+ (pacmacs-down . 182)
+ (pacmacs-left . 184)
+ (pacmacs-up . 190)
+ (pacmacs-right . 192)
+ (pacmacs-up . 206)
+ (pacmacs-left . 208)
+ (pacmacs-down . 215)
+ (pacmacs-up . 221)
+ (pacmacs-right . 224)
+ (pacmacs-up . 235)
+ (pacmacs-left . 240)
+ (pacmacs-right . 254)
+ (pacmacs-left . 272)
+ (pacmacs-down . 279)
+ (pacmacs-up . 288)
+ (pacmacs-right . 290)
+ (pacmacs-up . 297)
+ (pacmacs-left . 304)
+ (pacmacs-right . 322)
+ (pacmacs-down . 330)
+ (pacmacs-left . 335)
+ (pacmacs-up . 342)
+ (pacmacs-right . 344)
+ (pacmacs-up . 352)
+ (pacmacs-left . 356)
+ (pacmacs-right . 367)
+ (pacmacs-left . 379)
+ (pacmacs-right . 398)
+ (pacmacs-down . 407)
+ (pacmacs-left . 410)
+ (pacmacs-down . 443)
+ (pacmacs-left . 458)
+ (pacmacs-up . 466)
+ (pacmacs-right . 472)
+ (pacmacs-down . 482)
+ (pacmacs-left . 483)
+ (pacmacs-down . 491)
+ (pacmacs-right . 493)
+ (pacmacs-down . 503)
+ (pacmacs-left . 506)
+ (pacmacs-up . 517)
+ (pacmacs-right . 519)
+ (pacmacs-up . 527)
+ (pacmacs-left . 528)
+ (pacmacs-right . 536)
+ (pacmacs-left . 546)
+ (pacmacs-up . 564)
+ (pacmacs-right . 571)
+ (pacmacs-down . 583)
+ (pacmacs-down . 620)
+ (pacmacs-left . 625)
+ (pacmacs-down . 630)
+ (pacmacs-right . 631)
+ (pacmacs-left . 664)
+ (pacmacs-up . 669)
+ (pacmacs-right . 675)
+ (pacmacs-down . 683)
+ (pacmacs-left . 686)
+ (pacmacs-down . 691)
+ (pacmacs-left . 696)
+ (pacmacs-down . 703)
+ (pacmacs-up . 708)
+ (pacmacs-right . 714)
+ (pacmacs-up . 718)
+ (pacmacs-right . 720)
+ (pacmacs-right . 724)
+ (pacmacs-right . 726)
+ (pacmacs-left . 729)
+ (pacmacs-down . 729)
+ (pacmacs-up . 731)
+ (pacmacs-left . 751)
+ (pacmacs-up . 758)
+ (pacmacs-right . 766)
+ (pacmacs-down . 772)
+ (pacmacs-left . 774)
+ (pacmacs-down . 782)
+ (pacmacs-right . 789)
+ (pacmacs-left . 807)
+ (pacmacs-up . 814)
+ (pacmacs-right . 819)
+ (pacmacs-left . 849)
+ (pacmacs-up . 855)
+ (pacmacs-left . 863)
+ (pacmacs-right . 870)
+ (pacmacs-down . 879)
+ (pacmacs-left . 886)
+ (pacmacs-right . 890)
+ (pacmacs-left . 893)
+ (pacmacs-right . 899)
+ (pacmacs-left . 902)
+ (pacmacs-right . 905)
+ (pacmacs-up . 911)
+ (pacmacs-right . 915)
+ (pacmacs-up . 917)
+ (pacmacs-right . 920)
+ (pacmacs-left . 926)
+ (pacmacs-right . 928)
+ (pacmacs-right . 937)
+ (pacmacs-left . 941))
diff --git a/it-cases/it-case03.el b/it-cases/it-case03.el
new file mode 100644
index 0000000000..9d38fc4cbc
--- /dev/null
+++ b/it-cases/it-case03.el
@@ -0,0 +1,63 @@
+((pacmacs-down . 7)
+ (pacmacs-right . 10)
+ (pacmacs-down . 14)
+ (pacmacs-right . 17)
+ (pacmacs-right . 21)
+ (pacmacs-left . 25)
+ (pacmacs-right . 29)
+ (pacmacs-down . 31)
+ (pacmacs-right . 35)
+ (pacmacs-down . 36)
+ (pacmacs-right . 41)
+ (pacmacs-up . 45)
+ (pacmacs-left . 47)
+ (pacmacs-up . 49)
+ (pacmacs-left . 52)
+ (pacmacs-right . 54)
+ (pacmacs-down . 56)
+ (pacmacs-left . 61)
+ (pacmacs-up . 66)
+ (pacmacs-left . 68)
+ (pacmacs-down . 73)
+ (pacmacs-left . 75)
+ (pacmacs-right . 78)
+ (pacmacs-up . 81)
+ (pacmacs-left . 85)
+ (pacmacs-up . 89)
+ (pacmacs-left . 92)
+ (pacmacs-up . 108)
+ (pacmacs-up . 111)
+ (pacmacs-up . 114)
+ (pacmacs-up . 116)
+ (pacmacs-right . 121)
+ (pacmacs-down . 124)
+ (pacmacs-right . 130)
+ (pacmacs-up . 133)
+ (pacmacs-right . 139)
+ (pacmacs-down . 141)
+ (pacmacs-right . 147)
+ (pacmacs-up . 149)
+ (pacmacs-right . 154)
+ (pacmacs-down . 156)
+ (pacmacs-left . 159)
+ (pacmacs-right . 161)
+ (pacmacs-down . 163)
+ (pacmacs-left . 166)
+ (pacmacs-right . 169)
+ (pacmacs-down . 171)
+ (pacmacs-right . 175)
+ (pacmacs-down . 178)
+ (pacmacs-up . 192)
+ (pacmacs-up . 214)
+ (pacmacs-right . 217)
+ (pacmacs-down . 220)
+ (pacmacs-right . 225)
+ (pacmacs-up . 228)
+ (pacmacs-right . 233)
+ (pacmacs-down . 236)
+ (pacmacs-right . 241)
+ (pacmacs-up . 246)
+ (pacmacs-down . 281)
+ (pacmacs-left . 282)
+ (pacmacs-down . 289)
+ (pacmacs-right . 291))
diff --git a/pacmacs-board.el b/pacmacs-board.el
index 837dfa91f6..68e5714c1a 100644
--- a/pacmacs-board.el
+++ b/pacmacs-board.el
@@ -69,6 +69,20 @@
                (equal object-type type)))
            cell)))
 
+(defun pacmacs--object-at-p (board row column objects)
+  (plist-bind ((width :width)
+               (height :height))
+      board
+    (let ((wrapped-row (mod row height))
+          (wrapped-column (mod column width)))
+      (-find (-lambda (object)
+               (plist-bind ((object-row :row)
+                            (object-column :column))
+                   object
+                 (and (= object-row wrapped-row)
+                      (= object-column wrapped-column))))
+             objects))))
+
 (defun pacmacs--step-point (board row column direction)
   (plist-bind ((width :width)
                (height :height))
diff --git a/pacmacs-score.el b/pacmacs-score.el
index 64c6e25f3e..75256cfb5f 100644
--- a/pacmacs-score.el
+++ b/pacmacs-score.el
@@ -32,6 +32,7 @@
 
 ;;; Code:
 
+(require 'f)
 (require 'dash)
 (require 'dash-functional)
 
@@ -53,7 +54,7 @@
 (defun pacmacs--read-score-table ()
   (when (file-exists-p pacmacs--score-file-name)
     (-> pacmacs--score-file-name
-        (pacmacs--file-content)
+        (f-read-text)
         (read-from-string)
         (car))))
 
diff --git a/pacmacs-utils.el b/pacmacs-utils.el
index f4f603d9ac..2c14345a2f 100644
--- a/pacmacs-utils.el
+++ b/pacmacs-utils.el
@@ -72,15 +72,16 @@ side-effects."
     (cdr (assoc direction-vector
                 direction-table))))
 
-(defun pacmacs--file-content (filename)
-  (with-temp-buffer
-    (insert-file-contents filename)
-    (buffer-string)))
-
 (defun pacmacs--levelname-from-filename (filename)
   (when (string-match "\\(map[0-9]+\\)\\.txt" filename)
     (match-string 1 filename)))
 
+(defmacro pacmacs--measure-time (&rest body)
+  "Measure the time it takes to evaluate BODY."
+  `(let ((time (current-time)))
+     ,@body
+     (float-time (time-since time))))
+
 (provide 'pacmacs-utils)
 
 ;;; pacmacs.el ends here
diff --git a/pacmacs.el b/pacmacs.el
index 701ded9857..9d6b3f4cb4 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -38,6 +38,7 @@
 
 (require 'cl-lib)
 (require 'dash)
+(require 'f)
 
 (require 'pacmacs-anim)
 (require 'pacmacs-board)
@@ -508,7 +509,7 @@
   (let* ((lines (split-string (->> map-name
                                    (format "./maps/%s.txt")
                                    (pacmacs--find-resource-file)
-                                   (pacmacs--file-content))
+                                   (f-read-text))
                               "\n" t))
          (board-width (apply 'max (mapcar #'length lines)))
          (board-height (length lines)))
diff --git a/test/pacmacs-utils-test.el b/test/pacmacs-utils-test.el
index d323b4ff4c..168dfbaa76 100644
--- a/test/pacmacs-utils-test.el
+++ b/test/pacmacs-utils-test.el
@@ -10,8 +10,3 @@
   (should (equal "map06" (pacmacs--levelname-from-filename "map06.txt")))
   (should (not (pacmacs--levelname-from-filename "."))))
 
-(ert-deftest pacmacs--file-content-test ()
-  (with-mock
-   (should (equal "hello\n"
-                  (pacmacs--file-content
-                   "test-data/file-with-hello-string.txt")))))
diff --git a/tools/it-recorder.el b/tools/it-recorder.el
index e31424152d..8570a505ac 100644
--- a/tools/it-recorder.el
+++ b/tools/it-recorder.el
@@ -1,9 +1,12 @@
 (require 'pacmacs)
 
+(require 'dash)
+(require 'f)
 (require 'cl-lib)
 
 (defvar pacmacs--tick-counter 0)
 (defvar pacmacs--recorded-actions nil)
+(defvar pacmacs--tick-times nil)
 
 (defun pacmacs--record-action (action-name)
   (add-to-list 'pacmacs--recorded-actions
@@ -22,24 +25,29 @@
         (insert))
     (write-file filename)))
 
+(defun pacmacs--load-test-case (filename)
+  (-> (f-read-text filename)
+      (read-from-string)
+      (car)))
+
 (defun pacmacs-record-up ()
   (interactive)
-  (pacmacs--record-action 'up)
+  (pacmacs--record-action 'pacmacs-up)
   (pacmacs-up))
 
 (defun pacmacs-record-down ()
   (interactive)
-  (pacmacs--record-action 'down)
+  (pacmacs--record-action 'pacmacs-down)
   (pacmacs-down))
 
 (defun pacmacs-record-left ()
   (interactive)
-  (pacmacs--record-action 'left)
+  (pacmacs--record-action 'pacmacs-left)
   (pacmacs-left))
 
 (defun pacmacs-record-right ()
   (interactive)
-  (pacmacs--record-action 'right)
+  (pacmacs--record-action 'pacmacs-right)
   (pacmacs-right))
 
 (defun pacmacs-record-tick ()
@@ -47,6 +55,20 @@
   (cl-incf pacmacs--tick-counter)
   (pacmacs-tick))
 
+(defun pacmacs-replay-tick ()
+  (cl-incf pacmacs--tick-counter)
+
+  (add-to-list 'pacmacs--tick-times
+               (pacmacs--measure-time
+                (pacmacs-tick)))
+
+  (if (not pacmacs--recorded-actions)
+      (pacmacs-quit)
+    (-let ((((action . tick-number) . _) pacmacs--recorded-actions))
+      (when (= tick-number pacmacs--tick-counter)
+        (funcall action)
+        (setq pacmacs--recorded-actions (cdr pacmacs--recorded-actions))))))
+
 (define-derived-mode pacmacs-it-recorder-mode pacmacs-mode 
"pacmacs-it-recorder-mode"
   (define-key pacmacs-it-recorder-mode-map (kbd "<up>") 'pacmacs-record-up)
   (define-key pacmacs-it-recorder-mode-map (kbd "<down>") 'pacmacs-record-down)
@@ -58,3 +80,12 @@
   (pacmacs--initialize-game 'pacmacs-record-tick)
   (pacmacs-it-recorder-mode)
   (pacmacs--reset-recorder))
+
+(defun pacmacs--start-it-replayer (filename)
+  (interactive "fLoad test case: ")
+  (pacmacs--initialize-game 'pacmacs-replay-tick)
+  (pacmacs-mode)
+
+  (setq pacmacs--recorded-actions (pacmacs--load-test-case filename))
+  (setq pacmacs--tick-counter 0)
+  (setq pacmacs--tick-times nil))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]