bdd.gby

Similar documents
test.gby

fp.gby

haskell.gby

2

org/ghc/ Windows Linux RPM 3.2 GHCi GHC gcc javac ghc GHCi(ghci) GHCi Prelude> GHCi :load file :l file :also file :a file :reload :r :type expr :t exp


kyoto.gby

3 3.1 algebraic datatype data k = 1 1,1... 1,n1 2 2,1... 2,n2... m m,1... m,nm 1 m m m,1,..., m,nm m 1, 2,..., k 1 data Foo x y = Alice x [y] B

monad.gby

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

Copyright c 2006 Zhenjiang Hu, All Right Reserved.

Copyright c 2008 Zhenjiang Hu, All Right Reserved.

連載 構文解析器結合子 山下伸夫 (( 株 ) タイムインターメディア ) 文字列の分解 1 1 Haskell lines Prelude lines :: String -> [String] lines "" = [] lines s = let (l,s'

2

第8回 関数

presen.gby

r03.dvi

Functional Programming

ohp03.dvi

ruby novice ruby novice ruby novice.

Q&A集

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

listings-ext

新・明解Java入門

r08.dvi

(CC Attribution) Lisp 2.1 (Gauche )

第9回 型とクラス

ohp08.dvi

1 # include < stdio.h> 2 # include < string.h> 3 4 int main (){ 5 char str [222]; 6 scanf ("%s", str ); 7 int n= strlen ( str ); 8 for ( int i=n -2; i

第12回 モナドパーサ


Ruby Ruby ruby Ruby G: Ruby>ruby Ks sample1.rb G: Ruby> irb (interactive Ruby) G: Ruby>irb -Ks irb(main):001:0> print( ) 44=>

r07.dvi

ohp07.dvi

VDM-SL VDM VDM-SL Toolbox VDM++ Toolbox 1 VDM-SL VDM++ Web bool

「プログラミング言語」 SICP 第4章 ~超言語的抽象~ その6

Parametric Polymorphism

Boo Boo 2 Boo 2.NET Framework SDK 2 Subversion 2 2 Java 4 NAnt 5 Boo 5 5 Boo if 11 for 11 range 12 break continue 13 pass

K227 Java 2

Ver.1 1/17/2003 2

Jacques Garrigue

RX600 & RX200シリーズ アプリケーションノート RX用仮想EEPROM

Exam : 1z1-809-JPN Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z1-809-JPN Exam's Question and Answers 1 from Ac

橡SPA2000.PDF

Functional Programming

tkk0408nari

10 (1) s 10.2 rails c Rails 7 > item = PlanItem.new => #<PlanItem id nil, name nil,...> > item.name = "" => "" > item.valid? => true valid? true false

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV


(1/2) 2/45 HPC top runner application programmer PC-9801F N88-BASIC Quick BASIC + DOS ( ) BCB Windows Percolation, Event-driven MD ActionScript Flash


( ) ( ) 30 ( ) 27 [1] p LIFO(last in first out, ) (push) (pup) 1

つくって学ぶプログラミング言語 RubyによるScheme処理系の実装

1. A0 A B A0 A : A1,...,A5 B : B1,...,B

fx-9860G Manager PLUS_J

test

離散数理工学 第 2回 数え上げの基礎:漸化式の立て方

ユニット・テストの概要

D0020.PDF


Microsoft PowerPoint - ProD0107.ppt

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

10-C.._241_266_.Z

ohp02.dvi

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");

r1.dvi

解きながら学ぶJava入門編

「Android Studioではじめる 簡単Androidアプリ開発」正誤表

/ , ,908 4,196 2, ,842 38, / / 2 33 /

Functional Programming

Exam : 1z0-809 日本語 (JPN) Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO 1 / 8 Get Latest & Valid 1z0-809-JPN Exam's Question and Answe

An introduction and future of Ruby coverage library


My関数の作成演習問題集

「計算と論理」 Software Foundations その4

JavaScript の使い方

unix15-script2_09.key

事例に見るSCORMの・・・


Condition DAQ condition condition 2 3 XML key value

Java (9) 1 Lesson Java System.out.println() 1 Java API 1 Java Java 1


# let rec sigma (f, n) = # if n = 0 then 0 else f n + sigma (f, n-1);; val sigma : (int -> int) * int -> int = <fun> sigma f n ( : * -> * ) sqsum cbsu

橡ボーダーライン.PDF

I 2 tutimura/ I 2 p.1/??

導入基礎演習.ppt

クックパッドのテスト自動化

RX501NC_LTE Mobile Router取説.indb

6 (1) app.html.eex 28 lib/nano_planner_web/templates/layout/app.html.eex 27 <footer> Oiax Inc <%= this_year() %> Oiax Inc. 29 </footer>

I HTML HashMap (i) (ii) :.java import java.net.*; import java.io.*; import java.util.hashmap; public class SimpleStopWatch { public static voi

Q&A集

1: Preference Display 1 package sample. pref ; 2 3 import android. app. Activity ; 4 import android. content. Intent ; 5 import android. content. Shar

国土技術政策総合研究所 研究資料

2018 IPSJ/SIGSE Software Engineering Symposium (SES2018) 1,a) 1,b) 1,c) Java 2014 Java Java Java Stream Optional 18% Stream 5% Stream JDK6/7

19 3!! (+) (>) (++) (+=) for while 3.1!! (20, 20) (1)(Blocks1.java) import javax.swing.japplet; import java.awt.graphics;

ML Edinburgh LCF ML Curry-Howard ML ( ) ( ) ( ) ( ) 1

US40cユーザーズガイド

中小企業の発展と政策支援

;y ;y ;; yy ;y;; yy y;y;y;y ;y; ;; yy ; y Portable CD player Operating Instructions RQT5364-S

Transcription:

Haskell Behavior Driven Development 2012.5.27 @kazu_yamamoto 1

Haskell 4 Mew Firemacs Mighty ghc-mod 2

Ruby/Java HackageDB 3

Haskeller 4

Haskeller 5

Q) Haskeller A) 6

7

Haskeller Haskell 8

9

10

Haskell 11

Haskell Haskell 12

13

Haskell 14

Haskell 15

Haskell 16

\^^/ 17

18

19

Haskeller HUnit QuickCheck 20

QuickCheck prop_doublesort :: [Int] -> Bool prop_doublesort xs = sort xs == sort (sort xs) > quickcheck prop_doublesort +++ OK, passed 100 tests. 21

22

Haskell QuickCheck sort :: Ord a => [a] -> [a] lookup :: Eq a => a -> [(a, b)] -> Maybe b delete :: Eq a => a -> [a] -> [a] HUnit ( ) hgetline :: Handle -> IO String writefile :: FilePath -> String -> IO () forkio :: IO () -> IO ThreadId 23

7 1946 12 24

25

26

QuickCheck QuickCheck prop_model x xs = linearsearch x xs == binarysearch x xs 27

QuickCheck 28

Haskeller 29

Simon HENGEL doctest 30

doctest Python def factorial(n): """Return the factorial of n, an exact integer >= 0. If the result is small enough to fit in an int, return an int. Else return a long. >>> [factorial(n) for n in range(6)] [1, 1, 2, 6, 24, 120] >>> factorial(30) 265252859812191058636308480000000L """ import math if not n >= 0: raise ValueError("n must be >= 0")... 31

Haskell Haddock 32

Haddock -- unlines is an inverse operation to lines. -- It joins lines, after appending a terminating -- newline to each. unlines :: [String] -> String unlines [] = [] unlines (l:ls) = l ++ \n : unlines ls Haddock HTML 33

">" Data.Map -- /O(1)/. Is the map empty? -- -- > Data.Map.null (empty) == True -- > Data.Map.null (singleton 1 a ) == False null :: Map k a -> Bool null Tip = True null (Bin _) = False 34

35

Simon HENGEL ">>>" >>> length [] 0 >>> writefile "tmpfile" "Hello" >>> readfile "tmpfile" "Hello" >>> head [] *** Exception: Prelude.head: empty list Haddock 2.8 36

doctest Haddock 0.5.2 Haddock API 0.6 GHC API GHCi doctest 0.6.x GHCi 0.7 GHCi 37

"prop>" prop> Data.Map.null empty == True prop> \xs -> sort xs == sort (sort (xs::[int])) prop> sort xs == sort (sort (xs::[int])) Haddock 38

haskell-src-exts... GHCi > sort xs == sort (sort (xs::[int])) <interactive>:1:6: Not in scope: xs <interactive>:1:24: Not in scope: xs "\xs -> " 39

doctest doctest 40

v2.3 QuickCheck > quickcheck $ length [] == 0 +++ OK, passed 100 tests. True 100 v2.4 > quickcheck $ length [] == 0 +++ OK, passed 1 tests. 41

/ > valid $ deletemin $ deletemin $ fromlist [(i,()) i <- [0,2,5,1,6,4,8,9,7,11,10,3]] False 42

Trystan SPANGLER Hspec 43

Q) Hspec A) Ruby Rspec Haskell Rspec BDD 44

Q) BDD (Behavior Driven Development) A) TDD (Test Driven Development) 45

Haskell 46

Hspec describe "deletemin" $ do it "maintains the balance even if applied doubly" $ valid $ deletemin $ deletemin $ fromlist [(i::int,()) i <- [0,2,5,1,6,4,8,9,7,11,10,3]] it... it... it... 47

IO setup teardown withdb action = bracket (connectsqlite3 "my.db") disconnect action describe "database adaptor" $ do it "returns 23, when 23 is selected" $ withdb $ \connection -> run connection "select 23;" shouldreturn 23 48

Haskell Behavior Driven Development 49

Haskell BDD (1) (1) rev :: [a] -> [a] rev = undefined undefined undefined undefined placeholders notimplemented todo 50

Haskell BDD (2) (2) Haddock -- -- rev @xs@ returns the elements of @xs@ -- in reverse order. @xs@ must be finite. -- -- >>> rev [1,2,3] -- [3,2,1] -- -- prop> rev [] == rev [] -- prop> rev (xs++ys) == rev ys ++ rev (xs::[int]) -- prop> rev (rev xs) == (xs::[int]) rev :: [a] -> [a] rev = undefined 51

Haskell BDD (3) (3) Hspec describe "rev" $ do it "returns the first element in the last" $ property $ \xs -> not (null xs) ==> head (rev xs) == last (xs :: [Int]) it "returns the last element in the first" $ property $ \xs -> not (null xs) ==> last (rev xs) == head (xs :: [Int]) 52

(4) Haskell BDD (4) rev :: [a] -> [a] rev = foldl (flip (:)) [] doctest Hspec Cabal cabal test test-suite doctests type: exitcode-stdio-1.0 main-is: doctests.hs build-depends: base, doctest test-suite spec type: exitcode-stdio-1.0 main-is: Spec.hs build-depends: base, hspec 53

rev = foldl (flip (:)) [] ghc-mod rev :: [a] -> [a] rev = foldl (flip (:)) [] -- -- >>> rev [1,2,3] -- [3,2,1] rev :: [a] -> [a] rev = foldl (flip (:)) [] 54

QuickCheck doctest Hspec ( ) Cabal 55

Simon HENGEL (doctest Hspec ) Hspec github issue 56