Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
aaee3b93
Commit
aaee3b93
authored
Nov 05, 2015
by
Hixie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more Gesture Arena tests
...and clean them up so it's easier to understand them.
parent
255ed0b9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
137 additions
and
215 deletions
+137
-215
arena_test.dart
packages/unit/test/gestures/arena_test.dart
+137
-215
No files found.
packages/unit/test/gestures/arena_test.dart
View file @
aaee3b93
...
@@ -3,239 +3,161 @@ import 'package:test/test.dart';
...
@@ -3,239 +3,161 @@ import 'package:test/test.dart';
typedef
void
GestureArenaCallback
(
Object
key
);
typedef
void
GestureArenaCallback
(
Object
key
);
class
TestGestureArenaMember
extends
GestureArenaMember
{
const
int
primaryKey
=
4
;
TestGestureArenaMember
({
this
.
onAcceptGesture
,
this
.
onRejectGesture
});
final
GestureArenaCallback
onAcceptGesture
;
final
GestureArenaCallback
onRejectGesture
;
class
TestGestureArenaMember
extends
GestureArenaMember
{
bool
acceptRan
=
false
;
void
acceptGesture
(
Object
key
)
{
void
acceptGesture
(
Object
key
)
{
onAcceptGesture
(
key
);
expect
(
key
,
equals
(
primaryKey
));
acceptRan
=
true
;
}
}
bool
rejectRan
=
false
;
void
rejectGesture
(
Object
key
)
{
void
rejectGesture
(
Object
key
)
{
onRejectGesture
(
key
);
expect
(
key
,
equals
(
primaryKey
));
rejectRan
=
true
;
}
}
}
}
void
main
(
)
{
class
GestureTester
{
test
(
'Should win by accepting'
,
()
{
GestureArena
arena
=
new
GestureArena
();
GestureArena
arena
=
new
GestureArena
();
TestGestureArenaMember
first
=
new
TestGestureArenaMember
();
TestGestureArenaMember
second
=
new
TestGestureArenaMember
();
int
primaryKey
=
4
;
GestureArenaEntry
firstEntry
;
bool
firstAcceptRan
=
false
;
void
addFirst
()
{
bool
firstRejectRan
=
false
;
firstEntry
=
arena
.
add
(
primaryKey
,
first
);
bool
secondAcceptRan
=
false
;
bool
secondRejectRan
=
false
;
TestGestureArenaMember
first
=
new
TestGestureArenaMember
(
onAcceptGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
firstAcceptRan
=
true
;
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
firstRejectRan
=
true
;
}
}
);
TestGestureArenaMember
second
=
new
TestGestureArenaMember
(
GestureArenaEntry
secondEntry
;
onAcceptGesture:
(
int
key
)
{
void
addSecond
()
{
expect
(
key
,
equals
(
primaryKey
));
secondEntry
=
arena
.
add
(
primaryKey
,
second
);
secondAcceptRan
=
true
;
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
secondRejectRan
=
true
;
}
}
);
GestureArenaEntry
firstEntry
=
arena
.
add
(
primaryKey
,
first
);
arena
.
add
(
primaryKey
,
second
);
arena
.
close
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isFalse
);
firstEntry
.
resolve
(
GestureDisposition
.
accepted
);
expect
(
firstAcceptRan
,
isTrue
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isTrue
);
});
test
(
'Should win by sweep'
,
()
{
void
expectNothing
()
{
GestureArena
arena
=
new
GestureArena
();
expect
(
first
.
acceptRan
,
isFalse
);
expect
(
first
.
rejectRan
,
isFalse
);
int
primaryKey
=
4
;
expect
(
second
.
acceptRan
,
isFalse
);
bool
firstAcceptRan
=
false
;
expect
(
second
.
rejectRan
,
isFalse
);
bool
firstRejectRan
=
false
;
bool
secondAcceptRan
=
false
;
bool
secondRejectRan
=
false
;
TestGestureArenaMember
first
=
new
TestGestureArenaMember
(
onAcceptGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
firstAcceptRan
=
true
;
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
firstRejectRan
=
true
;
}
}
);
TestGestureArenaMember
second
=
new
TestGestureArenaMember
(
void
expectFirstWin
()
{
onAcceptGesture:
(
int
key
)
{
expect
(
first
.
acceptRan
,
isTrue
);
expect
(
key
,
equals
(
primaryKey
));
expect
(
first
.
rejectRan
,
isFalse
);
secondAcceptRan
=
true
;
expect
(
second
.
acceptRan
,
isFalse
);
},
expect
(
second
.
rejectRan
,
isTrue
);
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
secondRejectRan
=
true
;
}
}
);
arena
.
add
(
primaryKey
,
first
);
arena
.
add
(
primaryKey
,
second
);
arena
.
close
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
void
expectSecondWin
()
{
expect
(
firstRejectRan
,
isFalse
);
expect
(
first
.
acceptRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
first
.
rejectRan
,
isTrue
);
expect
(
secondRejectRan
,
isFalse
);
expect
(
second
.
acceptRan
,
isTrue
);
expect
(
second
.
rejectRan
,
isFalse
);
}
}
arena
.
sweep
(
primaryKey
);
void
main
(
)
{
test
(
'Should win by accepting'
,
()
{
GestureTester
tester
=
new
GestureTester
();
tester
.
addFirst
();
tester
.
addSecond
();
tester
.
arena
.
close
(
primaryKey
);
tester
.
expectNothing
();
tester
.
firstEntry
.
resolve
(
GestureDisposition
.
accepted
);
tester
.
expectFirstWin
();
});
expect
(
firstAcceptRan
,
isTrue
);
test
(
'Should win by sweep'
,
()
{
expect
(
firstRejectRan
,
isFalse
);
GestureTester
tester
=
new
GestureTester
();
expect
(
secondAcceptRan
,
isFalse
);
tester
.
addFirst
();
expect
(
secondRejectRan
,
isTrue
);
tester
.
addSecond
();
tester
.
arena
.
close
(
primaryKey
);
tester
.
expectNothing
();
tester
.
arena
.
sweep
(
primaryKey
);
tester
.
expectFirstWin
();
});
});
test
(
'Should win on release after hold sweep release'
,
()
{
test
(
'Should win on release after hold sweep release'
,
()
{
GestureArena
arena
=
new
GestureArena
();
GestureTester
tester
=
new
GestureTester
();
tester
.
addFirst
();
int
primaryKey
=
4
;
tester
.
addSecond
();
bool
firstAcceptRan
=
false
;
tester
.
arena
.
close
(
primaryKey
);
bool
firstRejectRan
=
false
;
tester
.
expectNothing
();
bool
secondAcceptRan
=
false
;
tester
.
arena
.
hold
(
primaryKey
);
bool
secondRejectRan
=
false
;
tester
.
expectNothing
();
tester
.
arena
.
sweep
(
primaryKey
);
TestGestureArenaMember
first
=
new
TestGestureArenaMember
(
tester
.
expectNothing
();
onAcceptGesture:
(
int
key
)
{
tester
.
arena
.
release
(
primaryKey
);
expect
(
key
,
equals
(
primaryKey
));
tester
.
expectFirstWin
();
firstAcceptRan
=
true
;
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
firstRejectRan
=
true
;
}
);
TestGestureArenaMember
second
=
new
TestGestureArenaMember
(
onAcceptGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
secondAcceptRan
=
true
;
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
secondRejectRan
=
true
;
}
);
arena
.
add
(
primaryKey
,
first
);
arena
.
add
(
primaryKey
,
second
);
arena
.
close
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isFalse
);
arena
.
hold
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isFalse
);
arena
.
sweep
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isFalse
);
arena
.
release
(
primaryKey
);
expect
(
firstAcceptRan
,
isTrue
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isTrue
);
});
});
test
(
'Should win on sweep after hold release sweep'
,
()
{
test
(
'Should win on sweep after hold release sweep'
,
()
{
GestureArena
arena
=
new
GestureArena
();
GestureTester
tester
=
new
GestureTester
();
tester
.
addFirst
();
int
primaryKey
=
4
;
tester
.
addSecond
();
bool
firstAcceptRan
=
false
;
tester
.
arena
.
close
(
primaryKey
);
bool
firstRejectRan
=
false
;
tester
.
expectNothing
();
bool
secondAcceptRan
=
false
;
tester
.
arena
.
hold
(
primaryKey
);
bool
secondRejectRan
=
false
;
tester
.
expectNothing
();
tester
.
arena
.
release
(
primaryKey
);
TestGestureArenaMember
first
=
new
TestGestureArenaMember
(
tester
.
expectNothing
();
onAcceptGesture:
(
int
key
)
{
tester
.
arena
.
sweep
(
primaryKey
);
expect
(
key
,
equals
(
primaryKey
));
tester
.
expectFirstWin
();
firstAcceptRan
=
true
;
});
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
firstRejectRan
=
true
;
}
);
TestGestureArenaMember
second
=
new
TestGestureArenaMember
(
onAcceptGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
secondAcceptRan
=
true
;
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
secondRejectRan
=
true
;
}
);
arena
.
add
(
primaryKey
,
first
);
arena
.
add
(
primaryKey
,
second
);
arena
.
close
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isFalse
);
arena
.
hold
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
test
(
'Only first winner should win'
,
()
{
expect
(
firstRejectRan
,
isFalse
);
GestureTester
tester
=
new
GestureTester
();
expect
(
secondAcceptRan
,
isFalse
);
tester
.
addFirst
();
expect
(
secondRejectRan
,
isFalse
);
tester
.
addSecond
();
tester
.
arena
.
close
(
primaryKey
);
tester
.
expectNothing
();
tester
.
firstEntry
.
resolve
(
GestureDisposition
.
accepted
);
tester
.
secondEntry
.
resolve
(
GestureDisposition
.
accepted
);
tester
.
expectFirstWin
();
});
arena
.
release
(
primaryKey
);
test
(
'Only first winner should win, regardless of order'
,
()
{
GestureTester
tester
=
new
GestureTester
();
tester
.
addFirst
();
tester
.
addSecond
();
tester
.
arena
.
close
(
primaryKey
);
tester
.
expectNothing
();
tester
.
secondEntry
.
resolve
(
GestureDisposition
.
accepted
);
tester
.
firstEntry
.
resolve
(
GestureDisposition
.
accepted
);
tester
.
expectSecondWin
();
});
expect
(
firstAcceptRan
,
isFalse
);
test
(
'Win before close is delayed to close'
,
()
{
expect
(
firstRejectRan
,
isFalse
);
GestureTester
tester
=
new
GestureTester
();
expect
(
secondAcceptRan
,
isFalse
);
tester
.
addFirst
();
expect
(
secondRejectRan
,
isFalse
);
tester
.
addSecond
();
tester
.
expectNothing
();
tester
.
firstEntry
.
resolve
(
GestureDisposition
.
accepted
);
tester
.
expectNothing
();
tester
.
arena
.
close
(
primaryKey
);
tester
.
expectFirstWin
();
});
arena
.
sweep
(
primaryKey
);
test
(
'Win before close is delayed to close, and only first winner should win'
,
()
{
GestureTester
tester
=
new
GestureTester
();
tester
.
addFirst
();
tester
.
addSecond
();
tester
.
expectNothing
();
tester
.
firstEntry
.
resolve
(
GestureDisposition
.
accepted
);
tester
.
secondEntry
.
resolve
(
GestureDisposition
.
accepted
);
tester
.
expectNothing
();
tester
.
arena
.
close
(
primaryKey
);
tester
.
expectFirstWin
();
});
expect
(
firstAcceptRan
,
isTrue
);
test
(
'Win before close is delayed to close, and only first winner should win, regardless of order'
,
()
{
expect
(
firstRejectRan
,
isFalse
);
GestureTester
tester
=
new
GestureTester
();
expect
(
secondAcceptRan
,
isFalse
);
tester
.
addFirst
();
expect
(
secondRejectRan
,
isTrue
);
tester
.
addSecond
();
tester
.
expectNothing
();
tester
.
secondEntry
.
resolve
(
GestureDisposition
.
accepted
);
tester
.
firstEntry
.
resolve
(
GestureDisposition
.
accepted
);
tester
.
expectNothing
();
tester
.
arena
.
close
(
primaryKey
);
tester
.
expectSecondWin
();
});
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment