<commit_before>// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package store

import (
	"fmt"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestCMAInit(t *testing.T) {
	store := NewCMAStore()
	data := store.Get(time.Now().Add(-time.Minute), time.Now())
	assert.Empty(t, len(data), time.Now())
}

func TestCMANilInsert(t *testing.T) {
	store := NewCMAStore()
	assert.Error(t, store.Put(TimePoint{time.Now(), nil}))
}

func TestCMAInsertNormal(t *testing.T) {
	store := NewCMAStore()
	now := time.Now()
	assert := assert.New(t)
	assert.NoError(store.Put(TimePoint{now, uint64(2)}))
	assert.NoError(store.Put(TimePoint{now.Add(-time.Second), uint64(1)}))
	assert.NoError(store.Put(TimePoint{now.Add(time.Second), uint64(3)}))
	assert.NoError(store.Put(TimePoint{now.Add(-2 * time.Second), uint64(0)}))
	actual := store.Get(time.Time{}, now)
	require.Len(t, actual, 3)
	actual = store.Get(time.Time{}, time.Time{})
	require.Len(t, actual, 4)
}

func TestCMAInsertTime(t *testing.T) {
	zeroTime := time.Time{}
	store := NewCMAStore()
	now := time.Now()
	assert := assert.New(t)

	// Errors
	assert.Error(store.Put(TimePoint{zeroTime, uint64(2)}))
	assert.Error(store.Put(TimePoint{zeroTime, nil}))

	// Put 2 values
	assert.NoError(store.Put(TimePoint{now, uint64(2)}))
	assert.NoError(store.Put(TimePoint{now, uint64(6)}))
	assert.NoError(store.Put(TimePoint{now.Add(2 * time.Second), uint64(0)}))
	assert.NoError(store.Put(TimePoint{now.Add(2 * time.Second), uint64(20)}))
	assert.NoError(store.Put(TimePoint{now.Add(2 * time.Second), uint64(10)}))
	assert.NoError(store.Put(TimePoint{now.Add(2 * time.Second), uint64(1000)}))

	// Get Invocation with values 2 and 4
	actual := store.Get(zeroTime, now)
	fmt.Println(actual)<commit_msg>Remove debug print in cma_store_test<commit_after>// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package store

import (
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestCMAInit(t *testing.T) {
	store := NewCMAStore()
	data := store.Get(time.Now().Add(-time.Minute), time.Now())
	assert.Empty(t, len(data), time.Now())
}

func TestCMANilInsert(t *testing.T) {
	store := NewCMAStore()
	assert.Error(t, store.Put(TimePoint{time.Now(), nil}))
}

func TestCMAInsertNormal(t *testing.T) {
	store := NewCMAStore()
	now := time.Now()
	assert := assert.New(t)
	assert.NoError(store.Put(TimePoint{now, uint64(2)}))
	assert.NoError(store.Put(TimePoint{now.Add(-time.Second), uint64(1)}))
	assert.NoError(store.Put(TimePoint{now.Add(time.Second), uint64(3)}))
	assert.NoError(store.Put(TimePoint{now.Add(-2 * time.Second), uint64(0)}))
	actual := store.Get(time.Time{}, now)
	require.Len(t, actual, 3)
	actual = store.Get(time.Time{}, time.Time{})
	require.Len(t, actual, 4)
}

func TestCMAInsertTime(t *testing.T) {
	zeroTime := time.Time{}
	store := NewCMAStore()
	now := time.Now()
	assert := assert.New(t)

	// Errors
	assert.Error(store.Put(TimePoint{zeroTime, uint64(2)}))
	assert.Error(store.Put(TimePoint{zeroTime, nil}))

	// Put 2 values
	assert.NoError(store.Put(TimePoint{now, uint64(2)}))
	assert.NoError(store.Put(TimePoint{now, uint64(6)}))
	assert.NoError(store.Put(TimePoint{now.Add(2 * time.Second), uint64(0)}))
	assert.NoError(store.Put(TimePoint{now.Add(2 * time.Second), uint64(20)}))
	assert.NoError(store.Put(TimePoint{now.Add(2 * time.Second), uint64(10)}))
	assert.NoError(store.Put(TimePoint{now.Add(2 * time.Second), uint64(1000)}))

	// Get Invocation with values 2 and 4
	actual := store.Get(zeroTime, now)
{'fraction_non_alphanumeric': 0.16443309934056582, 'fraction_numerical': 0.023824718145075516, 'mean_word_length': 4.8049382716049385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7452009', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1646, 'n_words': 379}