<commit_before>/**
 * @file captured_flag_test.go
 * @author <NAME> jollheef<AT>riseup.net
 * @license GNU AGPLv3
 * @date September, 2015
 * @brief test work with captured_flag table
 */

package steward_test

import (
	"log"
	"testing"
)

import "github.com/jollheef/tin_foil_hat/steward"

func TestCaptureFlag(t *testing.T) {

	db, err := openDB()

	defer db.Close()

	err = steward.CaptureFlag(db.db, 10, 20)
	if err != nil {
		log.Fatalln("Capture flag failed:", err)
	}
}

func TestGetCapturedFlags(t *testing.T) {

	db, err := openDB()

	defer db.Close()

	round := 1
	team_id := 1

	flg1 := steward.Flag{1, "f", round, team_id, 1, "1:2"}
	flg2 := steward.Flag{2, "b", round, team_id, 1, "1:2"}

	err = steward.AddFlag(db.db, flg1)
	if err != nil {
		log.Fatalln("Add flag failed:", err)
	}

	err = steward.AddFlag(db.db, flg2)
	if err != nil {
		log.Fatalln("Add flag failed:", err)
	}

	err = steward.CaptureFlag(db.db, flg1.ID, 20)
	err = steward.CaptureFlag(db.db, flg2.ID, 30)

	flags1, err := steward.GetCapturedFlags(db.db, round, 20)
	if err != nil {
		log.Fatalln("Get captured flags failed:", err)
	}

	if len(flags1) != 1 {
		log.Fatalln("Get captured flags more/less than added")
	}

	flags2, err := steward.GetCapturedFlags(db.db, round, 30)
	if err != nil {
		log.Fatalln("Get captured flags failed:", err)
	}

	if len(flags2) != 1 {
		log.Fatalln("Get captured flags more/less than added")
	}

	if flags1[0] != flg1 || flags2[0] != flg2 {
		log.Fatalln("Getted flags invalid", flags1[0], flg1, flags2[0], flg2)
	}
}

func TestAlreadyCaptured(t *testing.T) {

	db, err := openDB()

	defer db.Close()

	flg1 := steward.Flag{1, "f", 1, 1, 1, "1:2"}
	flg2 := steward.Flag{2, "b", 1, 1, 1, "1:2"}

	err = steward.CaptureFlag(db.db, flg1.ID, 20)
<commit_msg>Add keys to struct initializers [5]<commit_after>/**
 * @file captured_flag_test.go
 * @author <NAME> jollheef<AT>riseup.net
 * @license GNU AGPLv3
 * @date September, 2015
 * @brief test work with captured_flag table
 */

package steward_test

import (
	"log"
	"testing"
)

import "github.com/jollheef/tin_foil_hat/steward"

func TestCaptureFlag(t *testing.T) {

	db, err := openDB()

	defer db.Close()

	err = steward.CaptureFlag(db.db, 10, 20)
	if err != nil {
		log.Fatalln("Capture flag failed:", err)
	}
}

func TestGetCapturedFlags(t *testing.T) {

	db, err := openDB()

	defer db.Close()

	round := 1
	team_id := 1

	flg1 := steward.Flag{ID: 1, Flag: "f", Round: round, TeamID: team_id,
		ServiceID: 1, Cred: "1:2"}
	flg2 := steward.Flag{ID: 2, Flag: "b", Round: round, TeamID: team_id,
		ServiceID: 1, Cred: "1:2"}

	err = steward.AddFlag(db.db, flg1)
	if err != nil {
		log.Fatalln("Add flag failed:", err)
	}

	err = steward.AddFlag(db.db, flg2)
	if err != nil {
		log.Fatalln("Add flag failed:", err)
	}

	err = steward.CaptureFlag(db.db, flg1.ID, 20)
	err = steward.CaptureFlag(db.db, flg2.ID, 30)

	flags1, err := steward.GetCapturedFlags(db.db, round, 20)
	if err != nil {
		log.Fatalln("Get captured flags failed:", err)
	}

	if len(flags1) != 1 {
		log.Fatalln("Get captured flags more/less than added")
	}

	flags2, err := steward.GetCapturedFlags(db.db, round, 30)
	if err != nil {
		log.Fatalln("Get captured flags failed:", err)
	}

	if len(flags2) != 1 {
		log.Fatalln("Get captured flags more/less than added")
	}

	if flags1[0] != flg1 || flags2[0] != flg2 {
		log.Fatalln("Getted flags invalid", flags1[0], flg1, flags2[0], flg2)
	}
}

func TestAlreadyCaptured(t *testing.T) {

	db, err := openDB()

	defer db.Close()

	flg1 := steward.Flag{ID: 1, Flag: "f", Round: 1, TeamID: 1,
		ServiceID: 1, Cred: "1:2"}
	flg2 := steward.Flag{ID: 2, Flag: "b", Round: 1, TeamID: 1,
		ServiceID: 1, Cred: "1:2"}

	err = steward.CaptureFlag(db.db, flg1.ID, 20)

{'fraction_non_alphanumeric': 0.17084890549919915, 'fraction_numerical': 0.03657234383342232, 'mean_word_length': 3.8410852713178296, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7195321', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1531, 'n_words': 389}