<commit_before>﻿/* -*- coding: utf-8; mode: c++; tab-width: 3; indent-tabs-mode: nil -*-

Copyright 2014
<NAME>

This file is part of Abaclade.

Abaclade is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

Abaclade is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.

You should have received a copy of the GNU General Public License along with Abaclade. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------------------------*/

#include <abaclade.hxx>
#include <abaclade/testing/test_case.hxx>
#include <abaclade/map.hxx>


////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::test::map_basic

namespace abc {
namespace test {

class map_basic : public testing::test_case {
public:
   //! See testing::test_case::title().
   virtual istr title() override {
      return istr(ABC_SL("abc::map – basic operations"));
   }

   //! See testing::test_case::run().
   virtual void run() override {
      ABC_TRACE_FUNC(this);

      map<int, int> m;

      ABC_TESTING_ASSERT_EQUAL(m.size(), 0u);

      m.add(10, 100);
      ABC_TESTING_ASSERT_EQUAL(m.size(), 1u);
      ABC_TESTING_ASSERT_EQUAL(m[10], 100);

      m.add(20, 200);
      ABC_TESTING_ASSERT_EQUAL(m.size(), 2u);
      ABC_TESTING_ASSERT_EQUAL(m[10], 100);
      ABC_TESTING_ASSERT_EQUAL(m[20], 200);

      m.remove(10);
      ABC_TESTING_ASSERT_EQUAL(m.size(), 1u);
      ABC_TESTING_ASSERT_EQUAL(m[20], 200);

      m.add(22, 220);
      ABC_TESTING_ASSERT_EQUAL(m.size(), 2u);
      ABC_TESTING_ASSERT_EQUAL(m[20], 200);
      ABC_TESTING_ASSERT_EQUAL(m[22], 220);

      m.clear();
      ABC_TESTING_ASSERT_EQUAL(m.size(), 0u);

      m.add(11, 110);
      ABC_TESTING_ASSERT_EQUAL(m.size(), 1u);
      ABC_TESTING_ASSERT_EQUAL(m[11], 110);
   }
};

} //namespace test
} //namespace abc

ABC_TESTING_REGISTER_TEST_CASE(abc::test::map_basic)<commit_msg>Add more tests for abc::map<commit_after>﻿/* -*- coding: utf-8; mode: c++; tab-width: 3; indent-tabs-mode: nil -*-

Copyright 2014
<NAME>

This file is part of Abaclade.

Abaclade is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

Abaclade is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.

You should have received a copy of the GNU General Public License along with Abaclade. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------------------------*/

#include <abaclade.hxx>
#include <abaclade/testing/test_case.hxx>
#include <abaclade/map.hxx>


////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::test::map_basic

namespace abc {
namespace test {

class map_basic : public testing::test_case {
public:
   //! See testing::test_case::title().
   virtual istr title() override {
      return istr(ABC_SL("abc::map – basic operations"));
   }

   //! See testing::test_case::run().
   virtual void run() override {
      ABC_TRACE_FUNC(this);

      map<int, int> m;

      ABC_TESTING_ASSERT_EQUAL(m.size(), 0u);

      m.add(10, 100);
      ABC_TESTING_ASSERT_EQUAL(m.size(), 1u);
      ABC_TESTING_ASSERT_EQUAL(m[10], 100);

      m.add(20, 200);
      ABC_TESTING_ASSERT_EQUAL(m.size(), 2u);
      ABC_TESTING_ASSERT_EQUAL(m[10], 100);
      ABC_TESTING_ASSERT_EQUAL(m[20], 200);

      m.remove(10);
      ABC_TESTING_ASSERT_EQUAL(m.size(), 1u);
      ABC_TESTING_ASSERT_EQUAL(m[20], 200);

      m.add(22, 220);
      ABC_TESTING_ASSERT_EQUAL(m.size(), 2u);
      ABC_TESTING_ASSERT_EQUAL(m[20], 200);
      ABC_TESTING_ASSERT_EQUAL(m[22], 220);

      m.clear();
      ABC_TESTING_ASSERT_EQUAL(m.size(), 0u);

      m.add(11, 110);
      ABC_TESTING_ASSERT_EQUAL(m.size(), 1u);
      ABC_TESTING_ASSERT_EQUAL(m[11], 110);

      // Add enough key/value pairs until a resize occurs.
      int iKey = 11, iValue = 110;
      std::size_t iInitialCapacity = m.capacity();
      do {
         iKey += 11;
         iValue += 110;
         m.add(iKey, iValue);
      } while (m.capacity() == iInitialCapacity);
      /* Verify that some values are still there. Can’t check them all because we don’t know exactly
      how many we ended up adding. */
      ABC_TESTING_ASSERT_EQUAL(m[11], 110);
      ABC_TESTING_ASSERT_EQUAL(m[22], 220);
      ABC_TESTING_ASSERT_EQUAL(m[iKey - 11], iValue - 110);
      ABC_TESTING_ASSERT_EQUAL(m[iKey], iValue);
   }
};

} //namespace test
} //namespace abc

ABC_TESTING_REGISTER_TEST_CASE(abc::test::map_basic)
{'fraction_non_alphanumeric': 0.18917881811204912, 'fraction_numerical': 0.032041442824251726, 'mean_word_length': 2.563226247436774, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4195501', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1593, 'n_words': 449}