<commit_before>package health

import (
	"github.com/c9s/goprocinfo/linux"
	"reflect"
	"runtime"
	"testing"
)

func TestBundle(t *testing.T) {
	expected := Stats{
		CurrentMemoryUtilizationHeapSys: 0,
		CurrentMemoryUtilizationAlloc:   1,
		CurrentMemoryUtilizationActive:  12,
	}

	actual := Stats{
		CurrentMemoryUtilizationAlloc: 0,
	}<commit_msg>Added unit tests for Clone and Apply<commit_after>package health

import (
	"github.com/c9s/goprocinfo/linux"
	"reflect"
	"runtime"
	"testing"
)

func TestClone(t *testing.T) {
	initial := Stats{
		CurrentMemoryUtilizationHeapSys: 123,
	}

	cloned := initial.Clone()
	if !reflect.DeepEqual(initial, cloned) {
		t.Errorf("Expected %v, got %v", initial, cloned)
	}

	cloned[CurrentMemoryUtilizationActive] = 123211
	if reflect.DeepEqual(initial, cloned) {
		t.Error("Clone should be a distinct instance")
	}
}

func TestApply(t *testing.T) {
	var testData = []struct {
		healthFunc HealthFunc
		initial    Stats
		expected   Stats
	}{
		{
			Inc(CurrentMemoryUtilizationAlloc, 1),
			Stats{},
			Stats{
				CurrentMemoryUtilizationAlloc: 1,
			},
		},
		{
			Bundle(
				Inc(CurrentMemoryUtilizationAlloc, -12),
				Ensure(MaxMemoryUtilizationActive),
			),
			Stats{
				CurrentMemoryUtilizationAlloc: 4,
			},
			Stats{
				CurrentMemoryUtilizationAlloc: -8,
				MaxMemoryUtilizationActive:    0,
			},
		},
	}

	for _, record := range testData {
		actual := record.initial.Clone()
		actual.Apply(record.healthFunc)
		if !reflect.DeepEqual(record.expected, actual) {
			t.Errorf("Expected %v, got %v", record.expected, actual)
		}
	}
}

func TestBundle(t *testing.T) {
	expected := Stats{
		CurrentMemoryUtilizationHeapSys: 0,
		CurrentMemoryUtilizationAlloc:   1,
		CurrentMemoryUtilizationActive:  12,
	}

	actual := Stats{
		CurrentMemoryUtilizationAlloc: 0,
	}
{'fraction_non_alphanumeric': 0.11742006615214995, 'fraction_numerical': 0.015435501653803748, 'mean_word_length': 4.170940170940171, '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': '3581426', 'n_tokens_mistral': 714, 'n_tokens_neox': 624, 'n_words': 125}