<commit_before>package main

import (
	"fmt"
	"io/ioutil"
	"path/filepath"
	"testing"
	"time"
)

const equals = true

func assert(t *testing.T, a interface{}, mustEqual bool, b interface{}) {
	if mustEqual {
		if a != b {
			t.Fatalf("%v did not equal %v", a, b)
		}
	} else {
		if a == b {
			t.Fatalf("%v did equal %v", a, b)
		}
	}
}

func TestParseTick(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	entry, err := newTick("<2012-12-26 12:46:5;75942;60;3158;5632;1584;144>")
	assert(t, err, equals, nil)
	assert(t, entry, !equals, nil)
	assert(t, fmt.Sprintf("%d", entry.SensorID), equals, "75942")
	assert(t, entry.NextDataSession, equals, "60")
	assert(t, entry.BatteryVoltage, equals, 3158.0)
	assert(t, entry.Temperature, equals, int64(5632))
	assert(t, entry.Humidity, equals, int64(1584))
	assert(t, entry.RadioQuality, equals, int64(144))
}

func TestParseDateTime(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	entry, err := newTick("<2012-12-26 12:46:5;75942;60;3158;5632;1584;144>")
	assert(t, err, equals, nil)
	assert(t, entry, !equals, nil)
	assert(t, entry.Datetime.Year(), equals, 2012)
	assert(t, entry.Datetime.Month(), equals, time.December)
	assert(t, entry.Datetime.Day(), equals, 26)
	assert(t, entry.Datetime.Hour(), equals, 12)
	assert(t, entry.Datetime.Minute(), equals, 46)
	assert(t, entry.Datetime.Second(), equals, 5)
	name, _ := entry.Datetime.Zone()
	assert(t, name, equals, "UTC")
}

func TestParseDateTimeMonthAndDayNotPadded(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	entry, err := newTick("<2012-2-5 12:46:5;75942;60;3158;5632;1584;144>")
	assert(t, err, equals, nil)
	assert(t, entry, !equals, nil)
	assert(t, entry.Datetime.Year(), equals, 2012)
	assert(t, entry.Datetime.Month(), equals, time.February)
	assert(t, entry.Datetime.Day(), equals, 5)
	assert(t, entry.Datetime.Hour(), equals, 12)
	assert(t, entry.Datetime.Minute(), equals, 46)
	assert(t, entry.Datetime.Second(), equals, 5)
	name, _ := entry.Datetime.Zone()
	assert(t, name, equals, "UTC")
}

func TestParseDateTimeWithPaddedSeconds(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	entry, err := newTick("<2012-12-26 12:46:05;75942;60;3158;5632;1584;144>")
	assert(t, err, equals, nil)
	assert(t, entry, !equals, nil)
	assert(t, entry.Datetime.Second(), equals, 5)
}

func TestParseDateTimeSeconds(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	entry, err := newTick("<2012-12-26 12:46:35;75942;60;3158;5632;1584;144>")
	assert(t, err, equals, nil)
	assert(t, entry, !equals, nil)
	assert(t, entry.Datetime.Second(), equals, 35)
}

func TestParseDateTimeMinutes(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	entry, err := newTick("<2012-12-26 13:2:36;75942;10;3202;6784;1580;150>")
	assert(t, err, equals, nil)
	assert(t, entry, !equals, nil)
	assert(t, entry.Datetime.Minute(), equals, 2)
}

func TestProcessTicks(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	b, err := ioutil.ReadFile(filepath.Join("testdata", "testfile.txt"))
	assert(t, err, equals, nil)
	count, err := processTicks(string(b), newTick)
	assert(t, err, equals, nil)
	assert(t, count, equals, 107)
}

func TestProcessExample(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	b, err := ioutil.ReadFile(filepath.Join("testdata", "example.txt"))
	assert(t, err, equals, nil)
	count, err := processTicks(string(b), newTick)
	assert(t, err, equals, nil)
	assert(t, count, equals, 5)
}

func TestProcessSingleLineExample(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	count, err := processTicks("<2013-4-7 10:24:39;426842;60;3135;6656;2312;126>", newTick)
	assert(t, err, equals, nil)
	assert(t, count, equals, 1)
}

func TestProcessSingleLineStartingWithR(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	count, err := processTicks("\r<2013-4-7 10:24:39;426842;60;3135;6656;2312;126>", newTick)
	assert(t, err, equals, nil)
	assert(t, count, equals, 1)
}

func TestDecodeTemperature(t *testing.T) {
	assert(t, decodeTemperature(5056), equals, 19.5)
	assert(t, decodeTemperature(2528), equals, 9.5)
	assert(t, decodeTemperature(2240), equals, 8.5)
}<commit_msg>Fix tests<commit_after>package main

import (
	"fmt"
	"io/ioutil"
	"path/filepath"
	"testing"
	"time"
)

const equals = true

func assert(t *testing.T, a interface{}, mustEqual bool, b interface{}) {
	if mustEqual {
		if a != b {
			t.Fatalf("%v did not equal %v", a, b)
		}
	} else {
		if a == b {
			t.Fatalf("%v did equal %v", a, b)
		}
	}
}

func TestParseTick(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	entry, err := onUploadV1("<2012-12-26 12:46:5;75942;60;3158;5632;1584;144>")
	assert(t, err, equals, nil)
	assert(t, entry, !equals, nil)
	assert(t, fmt.Sprintf("%d", entry.SensorID), equals, "75942")
	assert(t, entry.NextDataSession, equals, "60")
	assert(t, entry.BatteryVoltage, equals, 3158.0)
	assert(t, entry.Temperature, equals, int64(5632))
	assert(t, entry.Humidity, equals, int64(1584))
	assert(t, entry.RadioQuality, equals, int64(144))
}

func TestParseDateTime(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	entry, err := onUploadV1("<2012-12-26 12:46:5;75942;60;3158;5632;1584;144>")
	assert(t, err, equals, nil)
	assert(t, entry, !equals, nil)
	assert(t, entry.Datetime.Year(), equals, 2012)
	assert(t, entry.Datetime.Month(), equals, time.December)
	assert(t, entry.Datetime.Day(), equals, 26)
	assert(t, entry.Datetime.Hour(), equals, 12)
	assert(t, entry.Datetime.Minute(), equals, 46)
	assert(t, entry.Datetime.Second(), equals, 5)
	name, _ := entry.Datetime.Zone()
	assert(t, name, equals, "UTC")
}

func TestParseDateTimeMonthAndDayNotPadded(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	entry, err := onUploadV1("<2012-2-5 12:46:5;75942;60;3158;5632;1584;144>")
	assert(t, err, equals, nil)
	assert(t, entry, !equals, nil)
	assert(t, entry.Datetime.Year(), equals, 2012)
	assert(t, entry.Datetime.Month(), equals, time.February)
	assert(t, entry.Datetime.Day(), equals, 5)
	assert(t, entry.Datetime.Hour(), equals, 12)
	assert(t, entry.Datetime.Minute(), equals, 46)
	assert(t, entry.Datetime.Second(), equals, 5)
	name, _ := entry.Datetime.Zone()
	assert(t, name, equals, "UTC")
}

func TestParseDateTimeWithPaddedSeconds(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	entry, err := onUploadV1("<2012-12-26 12:46:05;75942;60;3158;5632;1584;144>")
	assert(t, err, equals, nil)
	assert(t, entry, !equals, nil)
	assert(t, entry.Datetime.Second(), equals, 5)
}

func TestParseDateTimeSeconds(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	entry, err := onUploadV1("<2012-12-26 12:46:35;75942;60;3158;5632;1584;144>")
	assert(t, err, equals, nil)
	assert(t, entry, !equals, nil)
	assert(t, entry.Datetime.Second(), equals, 35)
}

func TestParseDateTimeMinutes(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	entry, err := onUploadV1("<2012-12-26 13:2:36;75942;10;3202;6784;1580;150>")
	assert(t, err, equals, nil)
	assert(t, entry, !equals, nil)
	assert(t, entry.Datetime.Minute(), equals, 2)
}

func TestProcessTicks(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	b, err := ioutil.ReadFile(filepath.Join("testdata", "testfile.txt"))
	assert(t, err, equals, nil)
	count, err := processTicks(string(b), onUploadV1)
	assert(t, err, equals, nil)
	assert(t, count, equals, 107)
}

func TestProcessExample(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	b, err := ioutil.ReadFile(filepath.Join("testdata", "example.txt"))
	assert(t, err, equals, nil)
	count, err := processTicks(string(b), onUploadV1)
	assert(t, err, equals, nil)
	assert(t, count, equals, 5)
}

func TestProcessSingleLineExample(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	count, err := processTicks("<2013-4-7 10:24:39;426842;60;3135;6656;2312;126>", onUploadV1)
	assert(t, err, equals, nil)
	assert(t, count, equals, 1)
}

func TestProcessSingleLineStartingWithR(t *testing.T) {
	redisPool = getRedisPool(*redisHost)
	defer redisPool.Close()
	count, err := processTicks("\r<2013-4-7 10:24:39;426842;60;3135;6656;2312;126>", onUploadV1)
	assert(t, err, equals, nil)
	assert(t, count, equals, 1)
}

func TestDecodeTemperature(t *testing.T) {
	assert(t, decodeTemperature(5056), equals, 19.5)
	assert(t, decodeTemperature(2528), equals, 9.5)
	assert(t, decodeTemperature(2240), equals, 8.5)
}
{'fraction_non_alphanumeric': 0.17322654462242562, 'fraction_numerical': 0.08329519450800915, 'mean_word_length': 5.839593114241001, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5058807', 'n_tokens_mistral': 3938, 'n_tokens_neox': 3492, 'n_words': 725}