1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66

media / learning / common / value_unittest.cc [blame]

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/learning/common/value.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace media {
namespace learning {

class LearnerValueTest : public testing::Test {};

TEST_F(LearnerValueTest, EqualStringsCompareAsEqual) {
  const char* value = "value";
  Value v1(value);
  Value v2(value);
  EXPECT_TRUE(v1 == v2);
}

TEST_F(LearnerValueTest, UnequalStringsDoNotCompareAsEqual) {
  Value v1("value");
  Value v2("nonvalue");
  EXPECT_TRUE(v1 != v2);
}

TEST_F(LearnerValueTest, ConstCharAndStdStringsCompareAsEqual) {
  const char* value_as_char = "value";
  std::string value_as_str(value_as_char);
  Value v1(value_as_char);
  Value v2(value_as_str);
  EXPECT_TRUE(v1 == v2);
}

TEST_F(LearnerValueTest, IntsCompareCorrectly) {
  const int i1 = 12345;
  const int i2 = 67890;
  Value v1(i1);
  Value v2(i1);
  Value v3(i2);
  EXPECT_TRUE(v1 == v2);
  EXPECT_TRUE(v1 >= v2);
  EXPECT_TRUE(v1 != v3);
  EXPECT_TRUE(v1 < v3);
  EXPECT_FALSE(v1 >= v3);
  EXPECT_FALSE(v3 < v1);
  EXPECT_FALSE(v3 < v3);
  EXPECT_FALSE(v1 < v1);
  EXPECT_TRUE(v1 >= v1);
  EXPECT_TRUE(v3 > v1);
  EXPECT_FALSE(v1 > v3);
  EXPECT_FALSE(v1 > v1);
  EXPECT_FALSE(v3 > v3);
}

TEST_F(LearnerValueTest, VariousTypesWork) {
  EXPECT_EQ(Value(1.2).value(), 1.2);
  EXPECT_EQ(Value(10).value(), 10);
  EXPECT_EQ(Value(static_cast<int64_t>(-10)).value(), -10);
  EXPECT_EQ(Value(static_cast<uint64_t>(10)).value(), 10);
  EXPECT_EQ(Value(true).value(), 1.0);
  EXPECT_EQ(Value(false).value(), 0.0);
}

}  // namespace learning
}  // namespace media