test_dataset_parser.cpp
Go to the documentation of this file.
1 /*
2 * ECVL - European Computer Vision Library
3 * Version: 1.0.0
4 * copyright (c) 2021, Università degli Studi di Modena e Reggio Emilia (UNIMORE), AImageLab
5 * Authors:
6 * Costantino Grana (costantino.grana@unimore.it)
7 * Federico Bolelli (federico.bolelli@unimore.it)
8 * Michele Cancilla (michele.cancilla@unimore.it)
9 * Laura Canalini (laura.canalini@unimore.it)
10 * Stefano Allegretti (stefano.allegretti@unimore.it)
11 * All rights reserved.
12 */
13 
14 #include "ecvl/core.h"
15 #include "ecvl/dataset_parser.h"
16 #ifdef ECVL_WITH_EXAMPLES
17 #include "dataset_path.h"
18 #endif
19 
20 #include <fstream>
21 #include <gmock/gmock.h>
22 #include <gtest/gtest.h>
23 
24 using namespace ecvl;
25 
26 #ifdef ECVL_WITH_EXAMPLES
27 TEST(DatasetParser, LoadExistingDataset)
28 {
29  Dataset d(CMAKE_CURRENT_SOURCE_DIR "/examples/data/mnist/mnist_reduced.yml");
30  EXPECT_EQ(d.name_, "MNIST");
31  EXPECT_EQ(d.classes_.size(), 10);
32  EXPECT_THAT(d.classes_, testing::ElementsAre("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
33  EXPECT_EQ(d.samples_.size(), 1000);
34 }
35 #endif
36 
37 TEST(DatasetParser, LoadNonExistingDataset)
38 {
39  EXPECT_THROW(Dataset d("idontexist"), std::runtime_error);
40 }
41 
42 TEST(DatasetParser, LoadNonExistingOrBadImage)
43 {
44  {
45  std::ofstream os("hello.yml");
46  os << "dataset: test\n"
47  "images:\n"
48  " - location: idontexist\n"
49  " label: hello.png\n";
50  }
51  {
52  std::ofstream os("hello.png");
53  os << "this is not a valid image";
54  }
55  Dataset d("hello.yml");
56  EXPECT_THROW(d.samples_.front().LoadImage(), std::runtime_error);
57  EXPECT_THROW(d.samples_.front().LoadImage(ColorType::GRAY, true), std::runtime_error);
58  remove("hello.yml");
59  remove("hello.png");
60 }
Definition: any.h:69
TEST(DatasetParser, LoadNonExistingDataset)
DeepHealth Dataset.
std::vector< Sample > samples_
Vector containing all the Dataset samples. See Sample.