<commit_before>package main

import (
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestFree(t *testing.T) {
	mh := new(MetricHandler)
	free := &Free{RawStatus: readFile("fixtures/free.txt")}
	stats, _ := mh.Collect(free)
	agg := aggregateStats(stats)
	assert.Equal(t, agg["free.mem.total"], 8177440)
	assert.Equal(t, agg["free.mem.used"], 7097488)
	assert.Equal(t, agg["free.mem.free"], 1079952)
	assert.Equal(t, agg["free.mem.buffers"], 1230276)
	assert.Equal(t, agg["free.mem.cached"], 1782336)

	assert.Equal(t, agg["free.swap.total"], 522236)
	assert.Equal(t, agg["free.swap.used"], 22176)
	assert.Equal(t, agg["free.swap.free"], 500060)
}<commit_msg>refactor test for "free"<commit_after>package main

import (
	"fmt"
	"github.com/stretchr/testify/assert"
	"testing"
)

var freeResult = map[string]int{
	"free.mem.total":   8177440,
	"free.mem.used":    7097488,
	"free.mem.free":    1079952,
	"free.mem.buffers": 1230276,
	"free.mem.cached":  1782336,
	"free.swap.total":  522236,
	"free.swap.used":   22176,
	"free.swap.free":   500060,
}

func TestFree(t *testing.T) {
	mh := new(MetricHandler)
	free := &Free{RawStatus: readFile("fixtures/free.txt")}
	stats, _ := mh.Collect(free)
	agg := aggregateStats(stats)
	for k, v := range freeResult {
		assert.Equal(t, agg[k], v, fmt.Sprintf("expected %s to have value %v but was %v", k, v, agg[k]))
	}
}
{'fraction_non_alphanumeric': 0.19092904169714703, 'fraction_numerical': 0.07607900512070227, 'mean_word_length': 4.846153846153846, 'pattern_counts': {'":': 8, '<': 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': '3981086', 'n_tokens_mistral': 637, 'n_tokens_neox': 554, 'n_words': 101}