import 'package:aitrainer_app/bloc/body_type/bodytype_bloc.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart' as test;
import 'package:flutter_test/flutter_test.dart';

class MockCustomerRepository extends Mock implements CustomerRepository {}

void main() {
  late BodytypeBloc bloc;

  TestWidgetsFlutterBinding.ensureInitialized();

  test.setUp(() {
    bloc = BodytypeBloc(repository: MockCustomerRepository());
  });

  test.tearDown(() {
    bloc.close();
  });

  test.test('initial state is correct', () {
    expect(bloc.state, BodytypeInitial());
  });

  group('getValueByWeight', () {
    test.test('check differnt weights and answers', () {
      List<int> weights = [0, 3, 7];
      List<int> answers = [1, 2, 3, 4, 5];

      expect(bloc.getValueByWeight(weights[0], answers[4]), 0);
      expect(bloc.getValueByWeight(weights[0], answers[3]), 1);
      expect(bloc.getValueByWeight(weights[0], answers[2]), 3);
      expect(bloc.getValueByWeight(weights[0], answers[1]), 5);
      expect(bloc.getValueByWeight(weights[0], answers[0]), 7);

      expect(bloc.getValueByWeight(weights[1], answers[4]), 3);
      expect(bloc.getValueByWeight(weights[1], answers[3]), 4);
      expect(bloc.getValueByWeight(weights[1], answers[2]), 6);
      expect(bloc.getValueByWeight(weights[1], answers[1]), 4);
      expect(bloc.getValueByWeight(weights[1], answers[0]), 3);

      expect(bloc.getValueByWeight(weights[2], answers[4]), 7);
      expect(bloc.getValueByWeight(weights[2], answers[3]), 5);
      expect(bloc.getValueByWeight(weights[2], answers[2]), 3);
      expect(bloc.getValueByWeight(weights[2], answers[1]), 1);
      expect(bloc.getValueByWeight(weights[2], answers[0]), 0);

      List<int> weights2 = [5, 5, 0];
      expect(bloc.getValueByWeight(weights2[0], answers[4]), 5);
      expect(bloc.getValueByWeight(weights2[0], answers[3]), 4);
      expect(bloc.getValueByWeight(weights2[0], answers[2]), 3);
      expect(bloc.getValueByWeight(weights2[0], answers[1]), 2);
      expect(bloc.getValueByWeight(weights2[0], answers[0]), 1);

      expect(bloc.getValueByWeight(weights2[2], answers[4]), 0);
      expect(bloc.getValueByWeight(weights2[2], answers[3]), 1);
      expect(bloc.getValueByWeight(weights2[2], answers[2]), 3);
      expect(bloc.getValueByWeight(weights2[2], answers[1]), 5);
      expect(bloc.getValueByWeight(weights2[2], answers[0]), 7);
    });
  });
}
