[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 60/87: Add compute-cpl tests
From: |
Andy Wingo |
Subject: |
[Guile-commits] 60/87: Add compute-cpl tests |
Date: |
Thu, 22 Jan 2015 17:30:15 +0000 |
wingo pushed a commit to branch wip-goops-refactor
in repository guile.
commit 3a680fff7a4add3fabe2226107107eca3dd00e1b
Author: Andy Wingo <address@hidden>
Date: Tue Jan 13 21:07:42 2015 +0100
Add compute-cpl tests
* test-suite/tests/goops.test: Add tests for compute-cpl based on
comments from goops.scm.
* module/oop/goops.scm (compute-std-cpl): Remove comment, and add
docstring.
(compute-cpl): Improve comment.
---
module/oop/goops.scm | 26 +++-----------------------
test-suite/tests/goops.test | 23 +++++++++++++++++++++++
2 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/module/oop/goops.scm b/module/oop/goops.scm
index bb421b4..82a3bf3 100644
--- a/module/oop/goops.scm
+++ b/module/oop/goops.scm
@@ -246,29 +246,8 @@
(define (is-a? obj class)
(and (memq class (class-precedence-list (class-of obj))) #t))
-
-;;; The standard class precedence list computation algorithm
-;;;
-;;; Correct behaviour:
-;;;
-;;; (define-class food ())
-;;; (define-class fruit (food))
-;;; (define-class spice (food))
-;;; (define-class apple (fruit))
-;;; (define-class cinnamon (spice))
-;;; (define-class pie (apple cinnamon))
-;;; => cpl (pie) = pie apple fruit cinnamon spice food object top
-;;;
-;;; (define-class d ())
-;;; (define-class e ())
-;;; (define-class f ())
-;;; (define-class b (d e))
-;;; (define-class c (e f))
-;;; (define-class a (b c))
-;;; => cpl (a) = a b d c e f object top
-;;;
-
(define (compute-std-cpl c get-direct-supers)
+ "The standard class precedence list computation algorithm."
(define (only-non-null lst)
(filter (lambda (l) (not (null? l))) lst))
@@ -300,7 +279,8 @@
c-direct-supers)
(list c-direct-supers))))))
-;; Bootstrap version.
+;; This version of compute-cpl is replaced with a generic function once
+;; GOOPS has booted.
(define (compute-cpl class)
(compute-std-cpl class class-direct-supers))
diff --git a/test-suite/tests/goops.test b/test-suite/tests/goops.test
index 724c0ee..7cf64fc 100644
--- a/test-suite/tests/goops.test
+++ b/test-suite/tests/goops.test
@@ -599,3 +599,26 @@
(pass-if-equal 100 (slot-ref a 'test))
(pass-if-equal 100 (slot-ref b 'test))
(pass-if-equal 200 (slot-ref c 'test)))))))
+
+(define-class <food> ())
+(define-class <fruit> (<food>))
+(define-class <spice> (<food>))
+(define-class <apple> (<fruit>))
+(define-class <cinnamon> (<spice>))
+(define-class <pie> (<apple> <cinnamon>))
+
+(define-class <d> ())
+(define-class <e> ())
+(define-class <f> ())
+(define-class <b> (<d> <e>))
+(define-class <c> (<e> <f>))
+(define-class <a> (<b> <c>))
+
+(with-test-prefix "compute-cpl"
+ (pass-if-equal "<pie>"
+ (list <pie> <apple> <fruit> <cinnamon> <spice> <food> <object> <top>)
+ (compute-cpl <pie>))
+
+ (pass-if-equal "<a>"
+ (list <a> <b> <d> <c> <e> <f> <object> <top>)
+ (compute-cpl <a>)))
- [Guile-commits] 48/87: Re-use the vtable "size" field for GOOPS nfields, (continued)
- [Guile-commits] 48/87: Re-use the vtable "size" field for GOOPS nfields, Andy Wingo, 2015/01/22
- [Guile-commits] 54/87: Cosmetic goops refactors., Andy Wingo, 2015/01/22
- [Guile-commits] 47/87: Move <class> initialization to Scheme, Andy Wingo, 2015/01/22
- [Guile-commits] 50/87: Reimplement inherit-applicable! in Scheme, Andy Wingo, 2015/01/22
- [Guile-commits] 45/87: Rewrite %initialize-object in Scheme, Andy Wingo, 2015/01/22
- [Guile-commits] 49/87: Reimplement %allocate-instance in Scheme, Andy Wingo, 2015/01/22
- [Guile-commits] 51/87: goops.c no longer knows about <class> slot allocation, Andy Wingo, 2015/01/22
- [Guile-commits] 57/87: GOOPS utils module cleanups, Andy Wingo, 2015/01/22
- [Guile-commits] 58/87: Fold (oop goops util) into (oop goops), Andy Wingo, 2015/01/22
- [Guile-commits] 61/87: scm_make cleanup, Andy Wingo, 2015/01/22
- [Guile-commits] 60/87: Add compute-cpl tests,
Andy Wingo <=
- [Guile-commits] 35/87: goops: use computed class slot offsets; untabify and fix whitepace, Andy Wingo, 2015/01/22
- [Guile-commits] 59/87: Scheme GOOPS cleanups, Andy Wingo, 2015/01/22
- [Guile-commits] 63/87: Commenting in goops.scm, Andy Wingo, 2015/01/22
- [Guile-commits] 64/87: More GOOPS comments, Andy Wingo, 2015/01/22
- [Guile-commits] 67/87: Convert emit-linear-dispatch to use match, Andy Wingo, 2015/01/22
- [Guile-commits] 66/87: More GOOPS cleanups, Andy Wingo, 2015/01/22
- [Guile-commits] 62/87: Narrative reordering in goops.scm, Andy Wingo, 2015/01/22
- [Guile-commits] 69/87: GOOPS class slot indices defined as inline values, Andy Wingo, 2015/01/22
- [Guile-commits] 70/87: Manipulate GOOPS vtable flags from Scheme, for speed, Andy Wingo, 2015/01/22
- [Guile-commits] 68/87: `match' refactor in goops.scm, Andy Wingo, 2015/01/22