<commit_before>#include "utils/Utils.h"
#include <shogun/base/class_list.h>
#include <shogun/classifier/svm/LibSVM.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/kernel/GaussianKernel.h>
#include <shogun/util/factory.h>

#include <gtest/gtest.h>

using namespace shogun;

class GaussianKernel;

TEST(Factory, kernel)
{
	auto* obj = kernel("GaussianKernel");
	EXPECT_TRUE(obj != nullptr);
	EXPECT_TRUE(dynamic_cast<CGaussianKernel*>(obj) != nullptr);
	delete obj;
}

TEST(Factory, machine)
{
	auto* obj = machine("LibSVM");
	EXPECT_TRUE(obj != nullptr);
	EXPECT_TRUE(dynamic_cast<CLibSVM*>(obj) != nullptr);
	delete obj;
}

TEST(Factory, features_from_matrix)
{
	SGMatrix<float64_t> mat(2, 3);
	auto* obj = features(mat);
	EXPECT_TRUE(obj != nullptr);
	EXPECT_TRUE(dynamic_cast<CDenseFeatures<float64_t>*>(obj) != nullptr);
	delete obj;
}

TEST(Factory, features_dense_from_file)
{
	std::string filename = "Factory-features_from_file.XXXXXX";

	SGMatrix<float64_t> mat(2, 3);
	mat.set_const(1);
	generate_temp_filename(const_cast<char*>(filename.c_str()));
	auto file_save = some<CCSVFile>(filename.c_str(), 'w');
	mat.save(file_save);
	file_save->close();

	auto file_load = some<CCSVFile>(filename.c_str(), 'r');
	auto* obj = features(file_load, PT_FLOAT64);
	EXPECT_TRUE(obj != nullptr);
	auto* cast = dynamic_cast<CDenseFeatures<float64_t>*>(obj);
	ASSERT_TRUE(cast != nullptr);
	auto loaded_mat = cast->get_feature_matrix();
	EXPECT_TRUE(loaded_mat.equals(mat));
	delete obj;

	EXPECT_EQ(std::remove(filename.c_str()), 0);
}

TEST(Factory, labels_from_file)
{
	std::string filename = "Factory-labels_from_file.XXXXXX";

	SGVector<float64_t> vec(3);
	vec.set_const(1);
	generate_temp_filename(const_cast<char*>(filename.c_str()));
	auto file_save = some<CCSVFile>(filename.c_str(), 'w');
	vec.save(file_save);
	file_save->close();

	auto file_load = some<CCSVFile>(filename.c_str(), 'r');
	auto* obj = labels(file_load);
	EXPECT_TRUE(obj != nullptr);
	auto* cast = dynamic_cast<CDenseLabels*>(obj);
	ASSERT_TRUE(cast != nullptr);
	auto loaded_vec = cast->get_labels();
	EXPECT_TRUE(loaded_vec.equals(vec));
	delete obj;

	EXPECT_EQ(std::remove(filename.c_str()), 0);
}<commit_msg>close file before closing to avoid errors on windows<commit_after>#include "utils/Utils.h"
#include <shogun/base/class_list.h>
#include <shogun/classifier/svm/LibSVM.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/kernel/GaussianKernel.h>
#include <shogun/util/factory.h>

#include <gtest/gtest.h>

using namespace shogun;

class GaussianKernel;

TEST(Factory, kernel)
{
	auto* obj = kernel("GaussianKernel");
	EXPECT_TRUE(obj != nullptr);
	EXPECT_TRUE(dynamic_cast<CGaussianKernel*>(obj) != nullptr);
	delete obj;
}

TEST(Factory, machine)
{
	auto* obj = machine("LibSVM");
	EXPECT_TRUE(obj != nullptr);
	EXPECT_TRUE(dynamic_cast<CLibSVM*>(obj) != nullptr);
	delete obj;
}

TEST(Factory, features_from_matrix)
{
	SGMatrix<float64_t> mat(2, 3);
	auto* obj = features(mat);
	EXPECT_TRUE(obj != nullptr);
	EXPECT_TRUE(dynamic_cast<CDenseFeatures<float64_t>*>(obj) != nullptr);
	delete obj;
}

TEST(Factory, features_dense_from_file)
{
	std::string filename = "Factory-features_from_file.XXXXXX";

	SGMatrix<float64_t> mat(2, 3);
	mat.set_const(1);
	generate_temp_filename(const_cast<char*>(filename.c_str()));
	auto file_save = some<CCSVFile>(filename.c_str(), 'w');
	mat.save(file_save);
	file_save->close();

	auto file_load = some<CCSVFile>(filename.c_str(), 'r');
	auto* obj = features(file_load, PT_FLOAT64);
	file_load->close();
	EXPECT_TRUE(obj != nullptr);
	auto* cast = dynamic_cast<CDenseFeatures<float64_t>*>(obj);
	ASSERT_TRUE(cast != nullptr);
	auto loaded_mat = cast->get_feature_matrix();
	EXPECT_TRUE(loaded_mat.equals(mat));
	delete obj;

	EXPECT_EQ(std::remove(filename.c_str()), 0);
}

TEST(Factory, labels_from_file)
{
	std::string filename = "Factory-labels_from_file.XXXXXX";

	SGVector<float64_t> vec(3);
	vec.set_const(1);
	generate_temp_filename(const_cast<char*>(filename.c_str()));
	auto file_save = some<CCSVFile>(filename.c_str(), 'w');
	vec.save(file_save);
	file_save->close();

	auto file_load = some<CCSVFile>(filename.c_str(), 'r');
	auto* obj = labels(file_load);
	file_load->close();
	EXPECT_TRUE(obj != nullptr);
	auto* cast = dynamic_cast<CDenseLabels*>(obj);
	ASSERT_TRUE(cast != nullptr);
	auto loaded_vec = cast->get_labels();
	EXPECT_TRUE(loaded_vec.equals(vec));
	delete obj;

	EXPECT_EQ(std::remove(filename.c_str()), 0);
}
{'fraction_non_alphanumeric': 0.1656619781201161, 'fraction_numerical': 0.009377093101138647, 'mean_word_length': 7.190127970749543, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 57, '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': '5883649', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1683, 'n_words': 272}