Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 62 additions & 14 deletions lib/blocks/pages/genealogical_tree/first_gen/first_gen_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,15 @@ class FirstGenCubit extends Cubit<AFirstGenState> {
}

void setIVStateIndexOne() {
Map<IVColor, bool> ivButtonsMap = Map<IVColor, bool>.from(_ivButtonsModel.ivButtonsMap);
List<IVColor> currentIVColorList = firstGenModel.firstGenMap[FirstGenIndex.one]!.ivColorList;
Map<IVColor, bool> ivButtonsMap = _initializeIVButtonsMap();
if (firstGenModel.hasNonDefaultIVColor(FirstGenIndex.one)) {
for (IVColor key in ivButtonsMap.keys) {
ivButtonsMap[key] = currentIVColorList.contains(key);
}
ivButtonsMap = _getSingledUnblockedIVButtonMap(FirstGenIndex.one);
}
emit(FirstGenIVButtonsState(ivButtonMap: ivButtonsMap));
}

void setIVStateIndexTwo() {
Map<IVColor, bool> ivButtonsMap = _updateMapFromPreviousMonster(FirstGenIndex.one);
Map<IVColor, bool> ivButtonsMap = _getSingleBlockedIVButtonMap(FirstGenIndex.one);
List<IVColor> currentIVColorList = firstGenModel.firstGenMap[FirstGenIndex.two]!.ivColorList;
if (firstGenModel.hasNonDefaultIVColor(FirstGenIndex.two)) {
for (IVColor key in ivButtonsMap.keys) {
Expand All @@ -58,11 +55,44 @@ class FirstGenCubit extends Cubit<AFirstGenState> {
emit(FirstGenIVButtonsState(ivButtonMap: ivButtonsMap));
}

void setIVStateIndexThree() {
Map<IVColor, bool> ivButtonsMap = _initializeIVButtonsMap();
if (firstGenModel.hasNonDefaultIVColor(FirstGenIndex.three)) {
ivButtonsMap = _getSingledUnblockedIVButtonMap(FirstGenIndex.three);
}
emit(FirstGenIVButtonsState(ivButtonMap: ivButtonsMap));
}

void setIVStateIndexFour() {
Map<IVColor, bool> ivButtonsMap = _initializeIVButtonsMap();

if (firstGenModel.hasNonDefaultIVColor(FirstGenIndex.four)) {
ivButtonsMap = _getSingledUnblockedIVButtonMap(FirstGenIndex.four);
} else {
Map<FirstGenIndex, List<IVColor>> ivColorMap = _getIVColorMap();

bool previousIVColorBool = _hasPreviousIVColor(FirstGenIndex.three);

if (previousIVColorBool) {
for (IVColor key in ivButtonsMap.keys) {
ivButtonsMap[key] = !ivColorMap.values.any((List<IVColor> ivColorList) => ivColorList.contains(key));
}
} else {
for (IVColor key in ivButtonsMap.keys) {
ivButtonsMap[key] = ivColorMap.entries
.where((MapEntry<FirstGenIndex, List<IVColor>> entry) => entry.key.value < FirstGenIndex.three.value)
.any((MapEntry<FirstGenIndex, List<IVColor>> entry) => entry.value.contains(key));
}
}
}
emit(FirstGenIVButtonsState(ivButtonMap: ivButtonsMap));
}

Map<IVColor, bool> getIVButtonsState() {
if (state is FirstGenIVButtonsState) {
return (state as FirstGenIVButtonsState).ivButtonMap;
} else {
return _initializeIVButtons();
return _initializeIVButtonsMap();
}
}

Expand Down Expand Up @@ -100,7 +130,7 @@ class FirstGenCubit extends Cubit<AFirstGenState> {
bool _isMonsterEnabled(FirstGenIndex firstGenIndex) {
if (firstGenIndex.value == 1) {
return true;
} else if (firstGenIndex.value > 2) {
} else if (firstGenIndex.value > 4) {
return false;
}

Expand All @@ -111,7 +141,22 @@ class FirstGenCubit extends Cubit<AFirstGenState> {
return firstGenModel.hasNonDefaultIVColor(previousIndex);
}

Map<IVColor, bool> _updateMapFromPreviousMonster(FirstGenIndex firstGenIndex) {
bool _hasPreviousIVColor(FirstGenIndex firstGenIndex) {
Map<FirstGenIndex, List<IVColor>> ivColorMap = _getIVColorMap();
List<IVColor> femaleIVColorList = ivColorMap[firstGenIndex]!;
bool hasIVColorBool = ivColorMap.entries
.where((MapEntry<FirstGenIndex, List<IVColor>> entry) => entry.key.value < firstGenIndex.value)
.any((MapEntry<FirstGenIndex, List<IVColor>> entry) => entry.value.contains(femaleIVColorList[0]));
return hasIVColorBool;
}

Map<FirstGenIndex, List<IVColor>> _getIVColorMap() {
Map<FirstGenIndex, List<IVColor>> ivColorMap = firstGenModel.firstGenMap.map(
(FirstGenIndex firstGenIndex, MonsterModel monsterModel) => MapEntry<FirstGenIndex, List<IVColor>>(firstGenIndex, monsterModel.ivColorList));
return ivColorMap;
}

Map<IVColor, bool> _getSingleBlockedIVButtonMap(FirstGenIndex firstGenIndex) {
Map<IVColor, bool> ivButtonsMap = Map<IVColor, bool>.from(_ivButtonsModel.ivButtonsMap);
List<IVColor> previousMonsterIVList = firstGenModel.firstGenMap[firstGenIndex]!.ivColorList;
for (IVColor key in ivButtonsMap.keys) {
Expand All @@ -120,13 +165,16 @@ class FirstGenCubit extends Cubit<AFirstGenState> {
return ivButtonsMap;
}

Map<FirstGenIndex, List<IVColor>> _getIVColorMap() {
Map<FirstGenIndex, List<IVColor>> ivColorMap = firstGenModel.firstGenMap.map(
(FirstGenIndex firstGenIndex, MonsterModel monsterModel) => MapEntry<FirstGenIndex, List<IVColor>>(firstGenIndex, monsterModel.ivColorList));
return ivColorMap;
Map<IVColor, bool> _getSingledUnblockedIVButtonMap(FirstGenIndex firstGenIndex) {
Map<IVColor, bool> ivButtonsMap = Map<IVColor, bool>.from(_ivButtonsModel.ivButtonsMap);
List<IVColor> currentIVColorList = firstGenModel.firstGenMap[firstGenIndex]!.ivColorList;
for (IVColor key in ivButtonsMap.keys) {
ivButtonsMap[key] = currentIVColorList.contains(key);
}
return ivButtonsMap;
}

Map<IVColor, bool> _initializeIVButtons() {
Map<IVColor, bool> _initializeIVButtonsMap() {
Map<IVColor, bool> ivButtonMap = Map<IVColor, bool>.from(_ivButtonsModel.ivButtonsMap);
return ivButtonMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ class SecondGenCubit extends Cubit<ASecondGenState> {
_firstGenCubit.firstGenModel.firstGenMap[fatherFirstGenIndex]!.ivColorList[0]
];

bool isAutoFilledBool = secondGenModel.secondGenMap[secondGenIndex]!.isAutoFilledBool;

if (parentsList.contains(IVColor.defaultColor) || isAutoFilledBool) {
if (parentsList.contains(IVColor.defaultColor)) {
secondGenModel.setDefaultValues(secondGenIndex);
} else {
secondGenModel.inheritIVFromParents(secondGenIndex, parentsList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class _FirstGenWidgetState extends State<FirstGenWidget> {
final Map<FirstGenIndex, VoidCallback> buttonMethods = <FirstGenIndex, VoidCallback>{
FirstGenIndex.one: firstGenCubit.setIVStateIndexOne,
FirstGenIndex.two: firstGenCubit.setIVStateIndexTwo,
FirstGenIndex.three: () {},
FirstGenIndex.four: () {},
FirstGenIndex.three: firstGenCubit.setIVStateIndexThree,
FirstGenIndex.four: firstGenCubit.setIVStateIndexFour,
FirstGenIndex.five: () {},
FirstGenIndex.six: () {},
FirstGenIndex.seven: () {},
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: breeder
description: "The Breeder App is designed to assist users in breeding monsters with perfect combat characteristics."
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 0.0.5
version: 0.0.6

environment:
sdk: ">=3.2.3"
Expand Down
109 changes: 109 additions & 0 deletions test/unit/blocs/genealogical_tree/first_gen/first_gen_cubit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,115 @@ Future<void> main() async {
});
});

group('Test of FirstGenCubit.setIVStateIndexThree()', () {
// Act
setUpAll(() {
actualFirstGenCubit = FirstGenCubit();
});

test('Should emit [FirstGenIVButtonsState] with [ivButtonMap where all IVColors has true values] when [third monster IV is not filled with IV]',
() {
//Arrange
Map<IVColor, bool> expectedIVButtonMap = Map<IVColor, bool>.from(ivButtonsModel.ivButtonsMap);

AFirstGenState expectedFirstGenState = FirstGenIVButtonsState(ivButtonMap: expectedIVButtonMap);

// Act
actualFirstGenCubit.setIVStateIndexThree();

// Assert
expect(actualFirstGenCubit.state, expectedFirstGenState);
});

test(
'Should emit [FirstGenIVButtonsState] with [ivButtonMap where only atkColor has true value] when [user choose attack IV for third monster]',
() {
//Arrange
late Map<IVColor, bool> expectedIVButtonMap = <IVColor, bool>{
for (IVColor ivColor in IVColor.values.where((IVColor ivColor) => ivColor != IVColor.defaultColor)) ivColor: false
};

expectedIVButtonMap[IVColor.atkColor] = true;
AFirstGenState expectedFirstGenState = FirstGenIVButtonsState(ivButtonMap: expectedIVButtonMap);

// Act
actualFirstGenCubit.setIVColors(FirstGenIndex.three, IVColor.atkColor);
actualFirstGenCubit.setIVStateIndexThree();

// Assert
expect(actualFirstGenCubit.state, expectedFirstGenState);
});
});

group('Test of FirstGenCubit.setIVStateIndexFour()', () {
// Act
setUpAll(() {
actualFirstGenCubit = FirstGenCubit();
});

test(
'Should emit [FirstGenIVButtonsState] with [ivButtonMap where atkColor and hpColor has false value] when [third monster is filled with attack IV and previous pair contain hp IV and attack IV] and [fourth monster is not filled with IV]',
() {
//Arrange
late Map<IVColor, bool> expectedIVButtonMap = <IVColor, bool>{
for (IVColor ivColor in IVColor.values.where((IVColor ivColor) => ivColor != IVColor.defaultColor)) ivColor: true
};

expectedIVButtonMap[IVColor.hpColor] = false;
expectedIVButtonMap[IVColor.atkColor] = false;

AFirstGenState expectedFirstGenState = FirstGenIVButtonsState(ivButtonMap: expectedIVButtonMap);

actualFirstGenCubit
..setIVColors(FirstGenIndex.one, IVColor.atkColor)
..setIVColors(FirstGenIndex.two, IVColor.hpColor)
..setIVColors(FirstGenIndex.three, IVColor.atkColor)
..setIVStateIndexFour();

expect(actualFirstGenCubit.state, expectedFirstGenState);
});

test(
'Should emit [FirstGenIVButtonsState] with [ivButtonMap where only atkColor and hpColor has true value] when [third monster is filled with speed IV and previous pair contain hp IV and attack IV] and [fourth monster is not filled with IV]',
() {
//Arrange
late Map<IVColor, bool> expectedIVButtonMap = <IVColor, bool>{
for (IVColor ivColor in IVColor.values.where((IVColor ivColor) => ivColor != IVColor.defaultColor)) ivColor: false
};

expectedIVButtonMap[IVColor.hpColor] = true;
expectedIVButtonMap[IVColor.atkColor] = true;

AFirstGenState expectedFirstGenState = FirstGenIVButtonsState(ivButtonMap: expectedIVButtonMap);

actualFirstGenCubit
..resetMonsterToDefaultIVColors(FirstGenIndex.three)
..setIVColors(FirstGenIndex.three, IVColor.speedColor)
..setIVStateIndexFour();

expect(actualFirstGenCubit.state, expectedFirstGenState);
});

test(
'Should emit [FirstGenIVButtonsState] with [ivButtonMap where only atkColor has true value] when [user choose attack IV for fourth monster]',
() {
//Arrange
late Map<IVColor, bool> expectedIVButtonMap = <IVColor, bool>{
for (IVColor ivColor in IVColor.values.where((IVColor ivColor) => ivColor != IVColor.defaultColor)) ivColor: false
};

expectedIVButtonMap[IVColor.atkColor] = true;
AFirstGenState expectedFirstGenState = FirstGenIVButtonsState(ivButtonMap: expectedIVButtonMap);

// Act
actualFirstGenCubit.setIVColors(FirstGenIndex.four, IVColor.atkColor);
actualFirstGenCubit.setIVStateIndexFour();

// Assert
expect(actualFirstGenCubit.state, expectedFirstGenState);
});
});

group('Tests of FirstGenCubit.resetMonsterToDefaultIVColors()', () {
// Act
setUpAll(() {
Expand Down