<commit_before>package highcharts

import (
    "testing"
    "net/http"
    "io/ioutil"
    "time"
    "code.google.com/p/go.net/websocket"
    "strconv"
)

func TestNewChart(t *testing.T){
    options := map[string]interface{}{
        "series":  []interface{}{
            map[string]interface{}{
                "name": "toto",
                "data": []int{1, 2, 3},
            },
        },
        "chart": map[string]interface{}{
            "type": "line",
        },
    }
    NewChart("/chart/", options)

    resp, err := http.Get("http://localhost:8080/chart/")
    if err != nil{
        t.Errorf("Error while loading chart page", err)
    }
    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil{
        t.Errorf("Error while reading chart page", err)
    }
    // fmt.Println(string(body))

    resp, err = http.Get("http://localhost:8080/chart/data/")
    if err != nil{
        t.Errorf("Error while loading chart data page", err)
    }
    defer resp.Body.Close()
    body, err = ioutil.ReadAll(resp.Body)
    if err != nil{
        t.Errorf("Error while reading chart data page", err)
    }
    if string(body) != "{\"chart\":{\"type\":\"line\"},\"series\":[{\"data\":[1,2,3],\"name\":\"toto\"}]}"{
        t.Errorf("Error in data json")
    }


    resp, err = http.Get("http://localhost:8080/static/js/highcharts.js")
    if err != nil{
        t.Errorf("Error while reading static page", err)
    }

    resp, err = http.Get("http://localhost:8080/static/js/load.js")
    if err != nil{
        t.Errorf("Error while reading static page", err)
    }
}

func TestDynamicChart(t *testing.T){
    options := map[string]interface{}{
        "series":  []interface{}{
            map[string]interface{}{
                "name": "toto",
                "data": []int{1, 2, 3},
            },
        },
    }

    data := make(chan interface{})
    NewDynamicChart("/dynamic/", options, data)
    go func(){
        for i := 0; i < 10; i++{<commit_msg>Simplified dynamic test.<commit_after>package highcharts

import (
    "testing"
    "net/http"
    "io/ioutil"
    "time"
    "code.google.com/p/go.net/websocket"
    "strconv"
)

func TestNewChart(t *testing.T){
    options := map[string]interface{}{
        "series":  []interface{}{
            map[string]interface{}{
                "name": "toto",
                "data": []int{1, 2, 3},
            },
        },
        "chart": map[string]interface{}{
            "type": "line",
        },
    }
    NewChart("/chart/", options)

    resp, err := http.Get("http://localhost:8080/chart/")
    if err != nil{
        t.Errorf("Error while loading chart page", err)
    }
    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil{
        t.Errorf("Error while reading chart page", err)
    }
    // fmt.Println(string(body))

    resp, err = http.Get("http://localhost:8080/chart/data/")
    if err != nil{
        t.Errorf("Error while loading chart data page", err)
    }
    defer resp.Body.Close()
    body, err = ioutil.ReadAll(resp.Body)
    if err != nil{
        t.Errorf("Error while reading chart data page", err)
    }
    if string(body) != "{\"chart\":{\"type\":\"line\"},\"series\":[{\"data\":[1,2,3],\"name\":\"toto\"}]}"{
        t.Errorf("Error in data json")
    }


    resp, err = http.Get("http://localhost:8080/static/js/highcharts.js")
    if err != nil{
        t.Errorf("Error while reading static page", err)
    }

    resp, err = http.Get("http://localhost:8080/static/js/load.js")
    if err != nil{
        t.Errorf("Error while reading static page", err)
    }
}

func TestDynamicChart(t *testing.T){
    data := make(chan interface{})
    NewDynamicChart("/dynamic/", nil, data)
    go func(){
        for i := 0; i < 10; i++{
{'fraction_non_alphanumeric': 0.1851170128845648, 'fraction_numerical': 0.013936366026820931, 'mean_word_length': 2.1832635983263597, 'pattern_counts': {'":': 23, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7013640', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1237, 'n_words': 276}