Skip to content

Commit 0b797eb

Browse files
authored
[Issue-114] Add test to sequential driver on same signal to return Exception (#197)
1 parent 9e786e5 commit 0b797eb

21 files changed

+486
-136
lines changed

lib/src/collections/collections.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Copyright (C) 2022 Intel Corporation
2+
/// SPDX-License-Identifier: BSD-3-Clause
3+
4+
export 'duplicate_detection_set.dart';
5+
export 'traverseable_collection.dart';
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/// Copyright (C) 2022 Intel Corporation
2+
/// SPDX-License-Identifier: BSD-3-Clause
3+
///
4+
/// redriven_monitor_set.dart
5+
/// A set that monitor for duplication.
6+
///
7+
/// 2022 November 2
8+
/// Author: Yao Jing Quek <[email protected]>
9+
///
10+
import 'dart:collection';
11+
import 'dart:core';
12+
13+
import 'package:collection/collection.dart';
14+
15+
/// A Set collection that monitor for duplication.
16+
///
17+
/// The [DuplicateDetectionSet] is used to identify
18+
/// duplicate elements in the Set.
19+
class DuplicateDetectionSet<T> extends SetBase<T> {
20+
/// The [Set] which contains unique values.
21+
final Set<T> _set = <T>{};
22+
23+
/// The [Set] which contains duplicate values.
24+
final Set<T> _duplicates = <T>{};
25+
26+
@override
27+
bool add(T value) {
28+
if (_set.contains(value)) {
29+
_duplicates.add(value);
30+
}
31+
32+
return _set.add(value);
33+
}
34+
35+
@override
36+
void addAll(Iterable<T> elements) {
37+
elements.forEach(add);
38+
}
39+
40+
/// The duplicate members in the collection
41+
///
42+
/// Returns an [UnmodifiableSetView] from DuplicateDetectionSet collection
43+
Set<T> get duplicates => UnmodifiableSetView(_duplicates);
44+
45+
/// Returns `true` if collection contains duplicates
46+
bool get hasDuplicates => _duplicates.isNotEmpty;
47+
48+
@override
49+
bool contains(Object? element) => _set.contains(element);
50+
51+
@override
52+
Iterator<T> get iterator => _set.iterator;
53+
54+
@override
55+
int get length => _set.length;
56+
57+
@override
58+
T? lookup(Object? element) => _set.lookup(element);
59+
60+
/// Removes value from [DuplicateDetectionSet] collection.
61+
///
62+
/// The [value] in [DuplicateDetectionSet] must not contain duplicates.
63+
/// An [Exception] will be thrown if duplicates [value] found.
64+
@override
65+
bool remove(Object? value) {
66+
if (_set.contains(value) && _duplicates.contains(value)) {
67+
throw Exception('Duplication value detected inside Set!');
68+
}
69+
return _set.remove(value);
70+
}
71+
72+
@override
73+
Set<T> toSet() => _set;
74+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// Copyright (C) 2022 Intel Corporation
2+
/// SPDX-License-Identifier: BSD-3-Clause
3+
4+
export 'signal_redriven_exception.dart';
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// Copyright (C) 2022 Intel Corporation
2+
/// SPDX-License-Identifier: BSD-3-Clause
3+
///
4+
/// signal_redriven_exception.dart
5+
/// An exception that thrown when a signal is
6+
/// redriven multiple times.
7+
///
8+
/// 2022 November 9
9+
/// Author: Yao Jing Quek <[email protected]>
10+
11+
import 'package:rohd/rohd.dart';
12+
13+
/// An exception that thrown when a [Logic] signal is
14+
/// operated multiple times.
15+
class SignalRedrivenException implements Exception {
16+
late final String _message;
17+
18+
/// Displays [signals] that are driven multiple times
19+
/// with default error [message].
20+
///
21+
/// Creates a [SignalRedrivenException] with an optional error [message].
22+
SignalRedrivenException(String signals,
23+
[String message = 'Sequential drove the same signal(s) multiple times: '])
24+
: _message = message + signals;
25+
26+
@override
27+
String toString() => _message;
28+
}

lib/src/exceptions/exceptions.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/// Copyright (C) 2022 Intel Corporation
22
/// SPDX-License-Identifier: BSD-3-Clause
33
4-
export 'name_exceptions.dart';
4+
export './conditionals/conditional_exceptions.dart';
5+
export './name/name_exceptions.dart';
6+
export './sim_compare/sim_compare_exceptions.dart';
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// Copyright (C) 2022 Intel Corporation
2+
/// SPDX-License-Identifier: BSD-3-Clause
3+
///
4+
/// invalid_reserved_name_exception.dart
5+
/// An exception that thrown when a reserved name is invalid.
6+
///
7+
/// 2022 October 25
8+
/// Author: Yao Jing Quek <[email protected]>
9+
///
10+
11+
/// An exception that thrown when a reserved name is invalid.
12+
class InvalidReservedNameException implements Exception {
13+
late final String _message;
14+
15+
/// Display error [message] on invalid reserved name.
16+
///
17+
/// Creates a [InvalidReservedNameException] with an optional error [message].
18+
InvalidReservedNameException(
19+
[String message = 'Reserved Name need to follow proper naming '
20+
'convention if reserved'
21+
' name set to true'])
22+
: _message = message;
23+
24+
@override
25+
String toString() => _message;
26+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Copyright (C) 2022 Intel Corporation
2+
/// SPDX-License-Identifier: BSD-3-Clause
3+
4+
export 'invalid_reserved_name_exception.dart';
5+
export 'null_reserved_name_exception.dart';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// Copyright (C) 2022 Intel Corporation
2+
/// SPDX-License-Identifier: BSD-3-Clause
3+
///
4+
/// null_reserved_name_exception.dart
5+
/// An exception that thrown when a reserved name is `null`.
6+
///
7+
/// 2022 November 15
8+
/// Author: Yao Jing Quek <[email protected]>
9+
///
10+
11+
/// An exception that thrown when a reserved name is `null`.
12+
class NullReservedNameException implements Exception {
13+
late final String _message;
14+
15+
/// Display error [message] on `null` reserved name.
16+
///
17+
/// Creates a [NullReservedNameException] with an optional error [message].
18+
NullReservedNameException(
19+
[String message = 'Reserved Name cannot be null '
20+
'if reserved name set to true'])
21+
: _message = message;
22+
23+
@override
24+
String toString() => _message;
25+
}

lib/src/exceptions/name_exceptions.dart

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)