<commit_before>package graph

import (
	"os"
	"testing"

	"github.com/gyuho/goraph/graph/testdata"
)

func TestNewDefaultGraphInterface(t *testing.T) {
	g := NewDefaultGraph()
	t.Log(g.String())
}

func TestNewDefaultGraphFromJSON(t *testing.T) {
	f, err := os.Open("testdata/graph.json")
	if err != nil {
		t.Error(err)
	}
	defer f.Close()
	g, err := newDefaultGraphFromJSON(f, "graph_00")
	if err != nil {
		t.Error(err)
	}
	// fmt.Println(g.String())
	if g.VertexToChildren["C"]["S"] != 9.0 {
		t.Errorf("weight from C to S must be 9.0 but %f", g.VertexToChildren["C"]["S"])
	}
	for _, graph := range testdata.GraphSlice {
		f, err := os.Open("testdata/graph.json")
		if err != nil {
			t.Error(err)
		}
		defer f.Close()
		g, err := newDefaultGraphFromJSON(f, graph.Name)
		if err != nil {
			t.Error(err)
		}
		if len(g.Vertices) != graph.TotalVertexCount {
			t.Errorf("%s | Expected %d but %d", graph.Name, graph.TotalVertexCount, len(g.Vertices))
		}<commit_msg>add more test cases for internal interface<commit_after>package graph

import (
	"os"
	"testing"

	"github.com/gyuho/goraph/graph/testdata"
)

func TestNewDefaultGraphInterface(t *testing.T) {
	g := NewDefaultGraph()
	t.Log(g.String())
	f, err := os.Open("testdata/graph.json")
	if err != nil {
		t.Error(err)
	}
	defer f.Close()
	_, err = NewDefaultGraphFromJSON(f, "graph_00")
	if err != nil {
		t.Error(err)
	}
}

func TestNewDefaultGraphFromJSON(t *testing.T) {
	f, err := os.Open("testdata/graph.json")
	if err != nil {
		t.Error(err)
	}
	defer f.Close()
	g, err := newDefaultGraphFromJSON(f, "graph_00")
	if err != nil {
		t.Error(err)
	}
	// fmt.Println(g.String())
	if g.VertexToChildren["C"]["S"] != 9.0 {
		t.Errorf("weight from C to S must be 9.0 but %f", g.VertexToChildren["C"]["S"])
	}
	for _, graph := range testdata.GraphSlice {
		f, err := os.Open("testdata/graph.json")
		if err != nil {
			t.Error(err)
		}
		defer f.Close()
		g, err := newDefaultGraphFromJSON(f, graph.Name)
		if err != nil {
			t.Error(err)
		}
		if len(g.Vertices) != graph.TotalVertexCount {
			t.Errorf("%s | Expected %d but %d", graph.Name, graph.TotalVertexCount, len(g.Vertices))
		}
{'fraction_non_alphanumeric': 0.17885421518397765, 'fraction_numerical': 0.006520726595249185, 'mean_word_length': 3.7417218543046356, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7290904', 'n_tokens_mistral': 900, 'n_tokens_neox': 859, 'n_words': 180}