mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:17:14 +00:00
f679efb946
Change-Id: Id4c9f5683b147f5f47df889b95477f6770e9c57e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132760 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
48 lines
1.6 KiB
Dart
48 lines
1.6 KiB
Dart
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'package:nnbd_migration/src/variables.dart';
|
|
import 'package:test/test.dart';
|
|
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
|
|
|
main() {
|
|
defineReflectiveSuite(() {
|
|
defineReflectiveTests(_UniqueIdentifierForSpanTest);
|
|
});
|
|
}
|
|
|
|
@reflectiveTest
|
|
class _UniqueIdentifierForSpanTest {
|
|
void test_inverse() {
|
|
const maxEnd = 1000;
|
|
for (int offset = 0; offset <= maxEnd; offset++) {
|
|
for (int end = offset; end <= maxEnd; end++) {
|
|
var uniqueId = Variables.uniqueIdentifierForSpan(offset, end);
|
|
var decoded = Variables.spanForUniqueIdentifier(uniqueId);
|
|
expect(decoded.offset, offset);
|
|
expect(decoded.end, end);
|
|
}
|
|
}
|
|
}
|
|
|
|
void test_uniqueness() {
|
|
const maxEnd = 1000;
|
|
const maxExpectedId = maxEnd * maxEnd;
|
|
var idsSeen = <int, String>{};
|
|
for (int offset = 0; offset <= maxEnd; offset++) {
|
|
for (int end = offset; end <= maxEnd; end++) {
|
|
var pairDescription = '($offset, $end)';
|
|
var uniqueId = Variables.uniqueIdentifierForSpan(offset, end);
|
|
expect(uniqueId, lessThanOrEqualTo(maxExpectedId));
|
|
var previousUseOfThisId = idsSeen[uniqueId];
|
|
expect(previousUseOfThisId, isNull,
|
|
reason:
|
|
'$pairDescription maps to $uniqueId, which was previously used '
|
|
'by $previousUseOfThisId');
|
|
idsSeen[uniqueId] = pairDescription;
|
|
}
|
|
}
|
|
}
|
|
}
|