Kata de TDD avec Guile et Emacs (String Calculator – 1)

Dans cette session...

Je me remet en jambe avant la rentrée avec un nouveau kata (l'intitulé est fourni en commentaire dans le code plus bas) ! Je cherche un moyen de rendre mes tests explicites ! Pour ce faire, je tente de combiner les symboles et les wildcards.

Ces kata sont pour moi un moyen d'améliorer mes compétences en développement logiciel. Je met l'accent sur :

Bon screencast !

Je place le code à la suite pour ceux que ça intéresse :

;; The method can take 0, 1 or 2 numbers, and will return their sum (for an empty string it will return 0) for example “” or “1” or “1,2”.
;; Allow the Add method to handle an unknown amount of numbers.
;; Allow the Add method to handle new lines between numbers (instead of commas).
;; The following input is ok: “1\n2,3”
;; The following input is NOT ok: “1,\n”
;; Calling Add with a negative number will throw an exception “negatives not allowed” - and the negative that was passed.
;; If multiple negatives are passed in, show all of them in the exception message.
;; Numbers bigger than 1024 should be ignored, so adding 2 + 1025 should equal 2.

(use-modules (srfi srfi-64))

(define (string-calculate numbers)
  (if (string-null? numbers)
      0
      (string->number numbers)))


(test-begin "test-suite")

(define EMPTY "")
(define ONE_NUMBER "1")
(define OTHER_ONE_NUMBER "2")
(define EMPTY_STRING_RESULT 0)

(define (a-string given _ expected)
  (test-equal (string-append "test-" given)
    expected
    (string-calculate given)))

(a-string EMPTY 'should-return EMPTY_STRING_RESULT)
(a-string ONE_NUMBER 'should-return 1)
(a-string OTHER_ONE_NUMBER 'should-return 2)

(test-end "test-suite")

Merci beaucoup d'avoir regardé ce screencast !

N'hésites pas à me donner ton avis, proposer une idée d'amélioration, laisser un commentaire, ou poser une question via :E-mail: jeremy AT korwin-zmijowski DOT frMastodon: @jeko@framapiaf.orgPeertube: @jeko@video.tedomum.netTwitter: @JeremyKorwin

Abonnes-toi pour ne pas manquer les prochains articles et épisodes:blog via Mastodon @jeko@write.as et RSSscreencast via Peertube @jeko@video.tedomum.net et RSS

Et encore plus important, partages le screencast et dis à tes amis que c'est le meilleur screencast de l'histoire du logiciel libre ! Sans dec'

#kata #tdd #testdrivendevelopment #guile #scheme #emacs #screencast #softwarecraftmanship #french