From bd338de72d55dabdcfaeea6ea5a3bc572514968c Mon Sep 17 00:00:00 2001 From: Pavel Jbanov Date: Sat, 26 Apr 2014 21:03:04 -0400 Subject: [PATCH] fix(Key): made key equality asymmetrical Fixes #94 --- lib/key.dart | 2 +- test/fixed-unittest.dart | 21 +-------------------- test/main.dart | 7 +++++++ 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/lib/key.dart b/lib/key.dart index be8154a..895af6c 100644 --- a/lib/key.dart +++ b/lib/key.dart @@ -12,7 +12,7 @@ class Key { final int id; factory Key(Type type, [Type annotation]) { - var _hashCode = type.hashCode + annotation.hashCode; + var _hashCode = type.hashCode + 2339 * annotation.hashCode; var _id = _hashToKey.putIfAbsent(_hashCode, () => _lastKeyId++); return new Key._newKey(type, annotation, _hashCode, _id); } diff --git a/test/fixed-unittest.dart b/test/fixed-unittest.dart index 831d81d..a157645 100644 --- a/test/fixed-unittest.dart +++ b/test/fixed-unittest.dart @@ -25,26 +25,7 @@ Matcher toThrow(Type exceptionClass, [message]) => message == null instanceOf(exceptionClass), message is Matcher ? message : toContain(message))); -Matcher not(Matcher matcher) => new NegateMatcher(matcher); - - -class NegateMatcher extends Matcher { - final Matcher _matcher; - - const NegateMatcher(this._matcher); - - bool matches(obj, Map ms) => !_matcher.matches(obj, ms); - - Description describe(Description description) => - _matcher.describe(description.add('NOT')); - - Description describeMismatch(item, Description mismatchDescription, - Map matchState, bool verbose) { - return _matcher.describeMismatch( - item, mismatchDescription, matchState, verbose); - } -} - +Matcher not(Matcher matcher) => isNot(matcher); class ThrowsMatcher extends Throws { final Matcher _matcher; diff --git a/test/main.dart b/test/main.dart index 6246d99..0941486 100644 --- a/test/main.dart +++ b/test/main.dart @@ -856,5 +856,12 @@ createKeySpec() { expect(k1, not(equals(k2))); expect(k1.hashCode, not(equals(k2.hashCode))); }); + + it('should not be symmetrically equal', () { + Key k1 = new Key(Engine, Old); + Key k2 = new Key(Old, Engine); + expect(k1, not(equals(k2))); + expect(k1.hashCode, not(equals(k2.hashCode))); + }); }); }