Created
February 10, 2019 06:35
-
-
Save ababup1192/ab3df2302ef807e2877fcc903472a656 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Tree | |
| = Node Tree Int Tree | |
| | Empty | |
| empty : Int -> Tree | |
| empty v = | |
| Node Empty v Empty | |
| sampleTree = | |
| Node | |
| (Node (empty 1) 3 (Node (empty 4) 6 (empty 7))) | |
| 8 | |
| (Node Empty 10 (Node (empty 13) 14 Empty)) | |
| treeView : Tree -> Html Msg | |
| treeView tree = | |
| case tree of | |
| Node left v right -> | |
| li [] | |
| [ a [ href "#" ] | |
| [ text <| String.fromInt v ] | |
| , ul [] | |
| [ treeView left | |
| , treeView right | |
| ] | |
| ] | |
| Empty -> | |
| li [] | |
| [ a [ href "#" ] [ text "" ] | |
| ] | |
| view : Model -> Html Msg | |
| view model = | |
| div [ class "container" ] | |
| [ div [ class "tree" ] | |
| [ ul [] | |
| [ treeView sampleTree | |
| ] | |
| ] | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| treeViewTest : Test | |
| treeViewTest = | |
| describe "treeView" | |
| [ describe "Emptyのとき" | |
| [ test "Emptyのときは、aタグの中が空文字である。" <| | |
| \() -> | |
| Empty | |
| |> treeView | |
| |> Query.fromHtml | |
| |> Query.find [ Selector.tag "a" ] | |
| |> Query.has [ Selector.text "" ] | |
| ] | |
| , describe "子を持たないノードのとき" <| | |
| let | |
| tree = | |
| Node Empty 1 Empty | |
| in | |
| [ test "根の数は一つである。" <| | |
| \() -> | |
| tree | |
| |> treeView | |
| |> Query.fromHtml | |
| |> Query.findAll [ Selector.tag "a" ] | |
| |> Query.first | |
| |> Query.has [ Selector.text "1" ] | |
| , test "左右の子は値を持たない。" <| | |
| \() -> | |
| tree | |
| |> treeView | |
| |> Query.fromHtml | |
| |> Query.find [ Selector.tag "ul" ] | |
| |> Query.findAll [ Selector.tag "a", Selector.text "" ] | |
| |> Query.count (Expect.equal 2) | |
| ] | |
| , describe "左に子を持つノードのとき" <| | |
| let | |
| tree = | |
| Node (empty 1) 2 Empty | |
| in | |
| [ test "根の数は一つである。" <| | |
| \() -> | |
| tree | |
| |> treeView | |
| |> Query.fromHtml | |
| |> Query.findAll [ Selector.tag "a" ] | |
| |> Query.first | |
| |> Query.has [ Selector.text "2" ] | |
| , test "左の子は値を持つ。" <| | |
| \() -> | |
| tree | |
| |> treeView | |
| |> Query.fromHtml | |
| |> Query.findAll [ Selector.tag "ul" ] | |
| |> Query.first | |
| |> Query.findAll [ Selector.tag "li" ] | |
| |> Query.first | |
| |> Query.has [ Selector.tag "a", Selector.text "1" ] | |
| ] | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment