#include "stdafx.h"

#include "xtr/core/SelectableSet.h"

class UTSelectableSet : public ::testing::Test {
protected:
  xtr::core::SelectableSet selection{};

  static constexpr EntityUID uid1{ 42U };
  static constexpr EntityUID uid2{ 1337U };
};

TEST_F(UTSelectableSet, Select) {
  EXPECT_EQ(size(selection.Selection()), 0U);
  EXPECT_FALSE(selection.IsSelected(uid1));

  selection.Select(uid1);
  EXPECT_EQ(size(selection.Selection()), 1U);
  EXPECT_TRUE(selection.IsSelected(uid1));
  EXPECT_FALSE(selection.IsSelected(uid2));

  selection.Select(uid1);
  EXPECT_EQ(size(selection.Selection()), 1U);
  EXPECT_TRUE(selection.IsSelected(uid1));
  EXPECT_FALSE(selection.IsSelected(uid2));

  selection.Select(uid2);
  EXPECT_EQ(size(selection.Selection()), 2U);
  EXPECT_TRUE(selection.IsSelected(uid1));
  EXPECT_TRUE(selection.IsSelected(uid2));
}

TEST_F(UTSelectableSet, SelectMultiple) {
  EXPECT_EQ(size(selection.Selection()), 0U);
  EXPECT_FALSE(selection.IsSelected(uid1));

  selection.SetSelection({ uid1, uid2 });
  EXPECT_EQ(size(selection.Selection()), 2U);
  EXPECT_TRUE(selection.IsSelected(uid1));
  EXPECT_TRUE(selection.IsSelected(uid2));

  selection.SetSelection({ uid1 });
  EXPECT_EQ(size(selection.Selection()), 1U);
  EXPECT_TRUE(selection.IsSelected(uid1));
  EXPECT_FALSE(selection.IsSelected(uid2));

  selection.SetSelection({});
  EXPECT_FALSE(selection.IsSelected(uid1));
  EXPECT_FALSE(selection.IsSelected(uid2));
}

TEST_F(UTSelectableSet, ResetSelection) {
  EXPECT_EQ(size(selection.Selection()), 0U);
  selection.ResetSelection();
  EXPECT_EQ(size(selection.Selection()), 0U);

  selection.SetSelection({ uid1, uid2 });
  EXPECT_EQ(size(selection.Selection()), 2U);
  selection.ResetSelection();
  EXPECT_EQ(size(selection.Selection()), 0U);
  EXPECT_FALSE(selection.IsSelected(uid1));
  EXPECT_FALSE(selection.IsSelected(uid2));
}