[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 35/61: Add compute-cpl tests
From: |
Andy Wingo |
Subject: |
[Guile-commits] 35/61: Add compute-cpl tests |
Date: |
Thu, 22 Jan 2015 18:53:11 +0000 |
wingo pushed a commit to branch wip-goops-refactor
in repository guile.
commit c0fb2c60fe46ef6c2078212b18a945acdaff9866
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 e0721f4..a8d1679 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] 19/61: No more concept of "pure generics", (continued)
- [Guile-commits] 19/61: No more concept of "pure generics", Andy Wingo, 2015/01/22
- [Guile-commits] 15/61: Move slot-ref et al to Scheme, Andy Wingo, 2015/01/22
- [Guile-commits] 21/61: Minor goops.c tidying, Andy Wingo, 2015/01/22
- [Guile-commits] 01/61: Deprecate C exports of GOOPS classes., Andy Wingo, 2015/01/22
- [Guile-commits] 22/61: Rewrite %initialize-object in Scheme, Andy Wingo, 2015/01/22
- [Guile-commits] 31/61: GOOPS cleanup to use SRFI-1 better, Andy Wingo, 2015/01/22
- [Guile-commits] 29/61: Incorporate %inherit-magic! into %init-layout!, Andy Wingo, 2015/01/22
- [Guile-commits] 32/61: append-map rather than mapappend, Andy Wingo, 2015/01/22
- [Guile-commits] 24/61: Move <class> initialization to Scheme, Andy Wingo, 2015/01/22
- [Guile-commits] 30/61: Cosmetic goops refactors., Andy Wingo, 2015/01/22
- [Guile-commits] 35/61: Add compute-cpl tests,
Andy Wingo <=
- [Guile-commits] 26/61: Reimplement %allocate-instance in Scheme, Andy Wingo, 2015/01/22
- [Guile-commits] 28/61: goops.c no longer knows about <class> slot allocation, Andy Wingo, 2015/01/22
- [Guile-commits] 34/61: Fold (oop goops util) into (oop goops), Andy Wingo, 2015/01/22
- [Guile-commits] 33/61: GOOPS utils module cleanups, Andy Wingo, 2015/01/22
- [Guile-commits] 27/61: Reimplement inherit-applicable! in Scheme, Andy Wingo, 2015/01/22
- [Guile-commits] 12/61: goops: use computed class slot offsets; untabify and fix whitepace, Andy Wingo, 2015/01/22
- [Guile-commits] 37/61: Narrative reordering in goops.scm, Andy Wingo, 2015/01/22
- [Guile-commits] 36/61: scm_make cleanup, Andy Wingo, 2015/01/22
- [Guile-commits] 39/61: More GOOPS comments, Andy Wingo, 2015/01/22
- [Guile-commits] 42/61: Convert emit-linear-dispatch to use match, Andy Wingo, 2015/01/22