Тестовая Вики-страница

Материал из Haskell.Ru
Перейти к: навигация, поиск

Тест на математические формулы:

[math]\int_a^x \!\!\!\int_a^s f(y)\,dy\,ds = \int_a^x f(y)(x-y)\,dy[/math]


[math]\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)[/math]


Тест на поддержку кода:

import Data.List (nub)
import System.IO.Unsafe	
import H3
import qualified WD
 
main = do
  addAjaxLogger
  serve [(root,0),(inst,1),(save,0),(snap,3),(restore,3),(delete,3)] $ 
   --Left [("GET",[]),("POST",["save"])]
   Right 3000
 
root a@[] = [URI$"root":a,Title"All instances",Get f] where
  f _ = [ LS"current"$ map ("Current instance: "++) a,
          LS"actions"$ map (\_->(li . linkTo $ save[])) a, 
          LS"instances"$ map (li . linkTo . \i->inst[i]) $ na ] where 
            a  = map instOf $ filter WD.isAlive l            
            na = nub . map instOf $ filter (not . WD.isAlive) l
            l = getList()
 
inst a@[i] = [URI$"inst":a,Title$"Instance "++i,Get f] where
  f _ = [ LS"snapshots"$ (map (li . linkTo . \(ts,st)->snap[i,ts,st]) $ getTSStore i) ]
 
save a@[] = [URI$"save":a,Title$"Save current state",Post act]
 
snap a = [URI$"snap":a,Title$"Snapshot "++showA3 a,Get f] where
  f _ = [ LS"actions"$ (map (li . linkTo . \p->p a) [restore,delete]) ]
 
restore a = [URI$"restore":a,Title$"Restore from "++showA3 a,Post act]
 
delete a = [URI$"delete":a,Title$"Delete "++showA3 a,Post act]
 
 
-- Utilities --
getList = \_-> unsafePerformIO WD.list  
 
instOf (i,_,_) = i
 
getTSStore i = map (\(_,ts,st)->(ts,show st)) $ filter p $ getList() where
  p (_,_,WD.Alive) = False 
  p (i',_,_) = i==i'
 
showA3 [i,ts,st] = i++"--"++ts++" from "++st 
 
 
-- Action-related -- 
 
act c = doJob (uri c) >>= return . f where
  f errs = [ S"status"$ concat $ g errs, S"redir"$ path $ redir $ uri c ]
  redir (_:i:_) = inst[i]
  redir _ = root[]
  g [] = ["Ok"]
  g l  = l
 
doJob :: [String] -> IO Errors
doJob = f where
  f ["save"] = WD.copyTo a WD.Attic
  f ["delete",i,ts,st] = WD.delete (i,ts,read st)
  f ["restore",i,ts,st] = WD.copyTo (i,ts,read st) WD.Alive
  Just a = WD.mbAlive l 
  l = getList()