Skip to content

Commit

Permalink
Added test for the metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
iboB committed Mar 2, 2017
1 parent 79c3f9f commit 7499cfd
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/dynamix/object_type_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class DYNAMIX_API object_type_info : private mixin_collection

#if DYNAMIX_ADDITIONAL_METRICS
// number of living objects with this type info
mutable size_t num_objects;
mutable size_t num_objects = 0;
#endif

// this should be called after the mixins have been initialized
Expand Down
82 changes: 82 additions & 0 deletions test/metrics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// DynaMix
// Copyright (c) 2013-2017 Borislav Stanimirov, Zahary Karadjov
//
// Distributed under the MIT Software License
// See accompanying file LICENSE.txt or copy at
// https://opensource.org/licenses/MIT
//
#include <dynamix/dynamix.hpp>

#include "mutation_rules/test_mixins.hpp"

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest/doctest.h"

TEST_SUITE("obj optional metrics");

using namespace dynamix;

TEST_CASE("metrics")
{
object o1;

auto& mta = _dynamix_get_mixin_type_info((a*)(nullptr));
auto& mtb = _dynamix_get_mixin_type_info((b*)(nullptr));
auto& mtc = _dynamix_get_mixin_type_info((c*)(nullptr));

CHECK(mta.num_mixins == 0);
CHECK(mtb.num_mixins == 0);
CHECK(mtc.num_mixins == 0);

mutate(o1)
.add<a>()
.add<b>();

auto t1 = o1._type_info;

CHECK(t1->num_objects == 1);
CHECK(mta.num_mixins == 1);
CHECK(mtb.num_mixins == 1);
CHECK(mtc.num_mixins == 0);

o1.clear();

CHECK(t1->num_objects == 0);
CHECK(mta.num_mixins == 0);
CHECK(mtb.num_mixins == 0);
CHECK(mtc.num_mixins == 0);

object o2;

mutate(o2)
.add<a>()
.add<b>();

CHECK(t1->num_objects == 1);
CHECK(mta.num_mixins == 1);
CHECK(mtb.num_mixins == 1);
CHECK(mtc.num_mixins == 0);

mutate(o1)
.add<a>()
.add<b>();

CHECK(t1->num_objects == 2);
CHECK(mta.num_mixins == 2);
CHECK(mtb.num_mixins == 2);
CHECK(mtc.num_mixins == 0);

mutate(o1)
.remove<a>()
.add<c>();

auto t2 = o1._type_info;

CHECK(t1->num_objects == 1);
CHECK(t2->num_objects == 1);
CHECK(mta.num_mixins == 1);
CHECK(mtb.num_mixins == 2);
CHECK(mtc.num_mixins == 1);

}

0 comments on commit 7499cfd

Please sign in to comment.