Skip to content

Commit

Permalink
[Issue-114] Add test to sequential driver on same signal to return Ex…
Browse files Browse the repository at this point in the history
…ception (#197)
  • Loading branch information
quekyj authored Dec 15, 2022
1 parent 9e786e5 commit 0b797eb
Show file tree
Hide file tree
Showing 21 changed files with 486 additions and 136 deletions.
5 changes: 5 additions & 0 deletions lib/src/collections/collections.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// Copyright (C) 2022 Intel Corporation
/// SPDX-License-Identifier: BSD-3-Clause
export 'duplicate_detection_set.dart';
export 'traverseable_collection.dart';
74 changes: 74 additions & 0 deletions lib/src/collections/duplicate_detection_set.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/// Copyright (C) 2022 Intel Corporation
/// SPDX-License-Identifier: BSD-3-Clause
///
/// redriven_monitor_set.dart
/// A set that monitor for duplication.
///
/// 2022 November 2
/// Author: Yao Jing Quek <[email protected]>
///
import 'dart:collection';
import 'dart:core';

import 'package:collection/collection.dart';

/// A Set collection that monitor for duplication.
///
/// The [DuplicateDetectionSet] is used to identify
/// duplicate elements in the Set.
class DuplicateDetectionSet<T> extends SetBase<T> {
/// The [Set] which contains unique values.
final Set<T> _set = <T>{};

/// The [Set] which contains duplicate values.
final Set<T> _duplicates = <T>{};

@override
bool add(T value) {
if (_set.contains(value)) {
_duplicates.add(value);
}

return _set.add(value);
}

@override
void addAll(Iterable<T> elements) {
elements.forEach(add);
}

/// The duplicate members in the collection
///
/// Returns an [UnmodifiableSetView] from DuplicateDetectionSet collection
Set<T> get duplicates => UnmodifiableSetView(_duplicates);

/// Returns `true` if collection contains duplicates
bool get hasDuplicates => _duplicates.isNotEmpty;

@override
bool contains(Object? element) => _set.contains(element);

@override
Iterator<T> get iterator => _set.iterator;

@override
int get length => _set.length;

@override
T? lookup(Object? element) => _set.lookup(element);

/// Removes value from [DuplicateDetectionSet] collection.
///
/// The [value] in [DuplicateDetectionSet] must not contain duplicates.
/// An [Exception] will be thrown if duplicates [value] found.
@override
bool remove(Object? value) {
if (_set.contains(value) && _duplicates.contains(value)) {
throw Exception('Duplication value detected inside Set!');
}
return _set.remove(value);
}

@override
Set<T> toSet() => _set;
}
4 changes: 4 additions & 0 deletions lib/src/exceptions/conditionals/conditional_exceptions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// Copyright (C) 2022 Intel Corporation
/// SPDX-License-Identifier: BSD-3-Clause
export 'signal_redriven_exception.dart';
28 changes: 28 additions & 0 deletions lib/src/exceptions/conditionals/signal_redriven_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// Copyright (C) 2022 Intel Corporation
/// SPDX-License-Identifier: BSD-3-Clause
///
/// signal_redriven_exception.dart
/// An exception that thrown when a signal is
/// redriven multiple times.
///
/// 2022 November 9
/// Author: Yao Jing Quek <[email protected]>
import 'package:rohd/rohd.dart';

/// An exception that thrown when a [Logic] signal is
/// operated multiple times.
class SignalRedrivenException implements Exception {
late final String _message;

/// Displays [signals] that are driven multiple times
/// with default error [message].
///
/// Creates a [SignalRedrivenException] with an optional error [message].
SignalRedrivenException(String signals,
[String message = 'Sequential drove the same signal(s) multiple times: '])
: _message = message + signals;

@override
String toString() => _message;
}
4 changes: 3 additions & 1 deletion lib/src/exceptions/exceptions.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// Copyright (C) 2022 Intel Corporation
/// SPDX-License-Identifier: BSD-3-Clause
export 'name_exceptions.dart';
export './conditionals/conditional_exceptions.dart';
export './name/name_exceptions.dart';
export './sim_compare/sim_compare_exceptions.dart';
26 changes: 26 additions & 0 deletions lib/src/exceptions/name/invalid_reserved_name_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// Copyright (C) 2022 Intel Corporation
/// SPDX-License-Identifier: BSD-3-Clause
///
/// invalid_reserved_name_exception.dart
/// An exception that thrown when a reserved name is invalid.
///
/// 2022 October 25
/// Author: Yao Jing Quek <[email protected]>
///
/// An exception that thrown when a reserved name is invalid.
class InvalidReservedNameException implements Exception {
late final String _message;

/// Display error [message] on invalid reserved name.
///
/// Creates a [InvalidReservedNameException] with an optional error [message].
InvalidReservedNameException(
[String message = 'Reserved Name need to follow proper naming '
'convention if reserved'
' name set to true'])
: _message = message;

@override
String toString() => _message;
}
5 changes: 5 additions & 0 deletions lib/src/exceptions/name/name_exceptions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// Copyright (C) 2022 Intel Corporation
/// SPDX-License-Identifier: BSD-3-Clause
export 'invalid_reserved_name_exception.dart';
export 'null_reserved_name_exception.dart';
25 changes: 25 additions & 0 deletions lib/src/exceptions/name/null_reserved_name_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// Copyright (C) 2022 Intel Corporation
/// SPDX-License-Identifier: BSD-3-Clause
///
/// null_reserved_name_exception.dart
/// An exception that thrown when a reserved name is `null`.
///
/// 2022 November 15
/// Author: Yao Jing Quek <[email protected]>
///
/// An exception that thrown when a reserved name is `null`.
class NullReservedNameException implements Exception {
late final String _message;

/// Display error [message] on `null` reserved name.
///
/// Creates a [NullReservedNameException] with an optional error [message].
NullReservedNameException(
[String message = 'Reserved Name cannot be null '
'if reserved name set to true'])
: _message = message;

@override
String toString() => _message;
}
48 changes: 0 additions & 48 deletions lib/src/exceptions/name_exceptions.dart

This file was deleted.

29 changes: 29 additions & 0 deletions lib/src/exceptions/sim_compare/non_supported_type_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// Copyright (C) 2022 Intel Corporation
/// SPDX-License-Identifier: BSD-3-Clause
///
/// non_supported_type_exception.dart
/// An exception that thrown when `runtimetype` of expected
/// vector output from SimCompare is invalid or unsupported.
///
/// 2022 November 17
/// Author: Yao Jing Quek <[email protected]>
///
import 'package:rohd/src/utilities/simcompare.dart';

/// An exception that thrown when `runtimeType` of expected vector
/// output from [SimCompare] is invalid or unsupported.
class NonSupportedTypeException implements Exception {
late final String _message;

/// Displays [vector] which have invalid or unsupported `runtimeType`
/// with default error [message].
///
/// Creates a [NonSupportedTypeException] with an optional error [message].
NonSupportedTypeException(String vector,
[String message = 'The runtimetype of expected vector is unsupported: '])
: _message = message + vector.runtimeType.toString();

@override
String toString() => _message;
}
4 changes: 4 additions & 0 deletions lib/src/exceptions/sim_compare/sim_compare_exceptions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// Copyright (C) 2022 Intel Corporation
/// SPDX-License-Identifier: BSD-3-Clause
export 'non_supported_type_exception.dart';
1 change: 1 addition & 0 deletions lib/src/logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'dart:async';

import 'package:collection/collection.dart';
import 'package:meta/meta.dart';

import 'package:rohd/rohd.dart';
import 'package:rohd/src/utilities/sanitizer.dart';
import 'package:rohd/src/utilities/synchronous_propagator.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:collection/collection.dart';
import 'package:meta/meta.dart';

import 'package:rohd/rohd.dart';
import 'package:rohd/src/exceptions/name_exceptions.dart';
import 'package:rohd/src/exceptions/name/name_exceptions.dart';
import 'package:rohd/src/utilities/config.dart';
import 'package:rohd/src/utilities/sanitizer.dart';
import 'package:rohd/src/utilities/uniquifier.dart';
Expand Down
Loading

0 comments on commit 0b797eb

Please sign in to comment.