protocols/src/test/java/eu/internetofus/common/protocols/Ask4HelpV2ProtocolWithAllFiltersITC.java
/**
   * Create the expected state.
   *
   * @param vertx       event bus to use.
   * @param testContext context to do the test.
   */
Create the expected state.
@param vertx       event bus to use.
@param testContext context to do the test.
Create the expected state . @param vertx event bus to use . @param testContext context to do the test .
@Test
  @Order(7)
  public void shouldCreateExpectedState(final Vertx vertx, final VertxTestContext testContext) {
    this.assertLastSuccessfulTestWas(6, testContext);
    this.expectedState = new JsonObject();
    final var whoToAskUsers = new JsonArray();
    this.expectedState.put("whoToAskUsers", whoToAskUsers);
    final var unaskedUserIds = new JsonArray();
    this.expectedState.put("unaskedUserIds", unaskedUserIds);
    final var socialClosenessUsers = new JsonArray();
    this.expectedState.put("socialClosenessUsers", socialClosenessUsers);
    final var closenessUsers = new JsonArray();
    this.expectedState.put("closenessUsers", closenessUsers);
    final var domainInterestUsers = new JsonArray();
    this.expectedState.put("domainInterestUsers", domainInterestUsers);
    final var beliefsAndValuesUsers = new JsonArray();
    this.expectedState.put("beliefsAndValuesUsers", beliefsAndValuesUsers);
    final var max = this.users.size();
    final var requester = this.users.get(0);
    final List<JsonObject> totals = new ArrayList<>();
    for (var i = 1; i < max; i++) {
      final var user = this.users.get(i);
      final var closeValue = 1.0 - UserDistance.calculateDistance(0, 0, 0.3 * i, 0.3 * i) / 1000000.0;
      final var socialValue = 0.1 * i;
      final var beliefValue = 1.0 - Math.abs(requester.meanings.get(0).level - user.meanings.get(0).level) / 2.0;
      final var domainValue = 1.0 - Math.abs(requester.competences.get(0).level - user.competences.get(0).level) / 2.0;
      final var total = closeValue * socialValue * beliefValue * domainValue;
      closenessUsers.add(new JsonObject().put("userId", user.id).put("value", closeValue));
      socialClosenessUsers.add(new JsonObject().put("userId", user.id).put("value", socialValue));
      domainInterestUsers.add(new JsonObject().put("userId", user.id).put("value", domainValue));
      beliefsAndValuesUsers.add(new JsonObject().put("userId", user.id).put("value", beliefValue));
      totals.add(new JsonObject().put("userId", user.id).put("value", total));
    }
    Collections.sort(totals, (a, b) -> b.getDouble("value").compareTo(a.getDouble("value")));
    for (final var whoToAskUser : totals) {
      whoToAskUsers.add(whoToAskUser);
      if (whoToAskUsers.size() > MAX_USERS) {
        unaskedUserIds.add(whoToAskUser.getString("userId"));
      }
    }
    this.assertSuccessfulCompleted(testContext);
  }
@ Test @ Order ( 7 ) public void shouldCreateExpectedState ( final Vertx vertx , final VertxTestContext testContext ) { this . assertLastSuccessfulTestWas ( 6 , testContext ) ; this . expectedState = new JsonObject ( ) ; final var whoToAskUsers = new JsonArray ( ) ; this . expectedState . put ( "whoToAskUsers" , whoToAskUsers ) ; final var unaskedUserIds = new JsonArray ( ) ; this . expectedState . put ( "unaskedUserIds" , unaskedUserIds ) ; final var socialClosenessUsers = new JsonArray ( ) ; this . expectedState . put ( "socialClosenessUsers" , socialClosenessUsers ) ; final var closenessUsers = new JsonArray ( ) ; this . expectedState . put ( "closenessUsers" , closenessUsers ) ; final var domainInterestUsers = new JsonArray ( ) ; this . expectedState . put ( "domainInterestUsers" , domainInterestUsers ) ; final var beliefsAndValuesUsers = new JsonArray ( ) ; this . expectedState . put ( "beliefsAndValuesUsers" , beliefsAndValuesUsers ) ; final var max = this . users . size ( ) ; final var requester = this . users . get ( 0 ) ; final List < JsonObject > totals = new ArrayList < > ( ) ; for ( var i = 1 ; i < max ; i ++ ) { final var user = this . users . get ( i ) ; final var closeValue = 1.0 - UserDistance . calculateDistance ( 0 , 0 , 0.3 * i , 0.3 * i ) / 1000000.0 ; final var socialValue = 0.1 * i ; final var beliefValue = 1.0 - Math . abs ( requester . meanings . get ( 0 ) . level - user . meanings . get ( 0 ) . level ) / 2.0 ; final var domainValue = 1.0 - Math . abs ( requester . competences . get ( 0 ) . level - user . competences . get ( 0 ) . level ) / 2.0 ; final var total = closeValue * socialValue * beliefValue * domainValue ; closenessUsers . add ( new JsonObject ( ) . put ( "userId" , user . id ) . put ( "value" , closeValue ) ) ; socialClosenessUsers . add ( new JsonObject ( ) . put ( "userId" , user . id ) . put ( "value" , socialValue ) ) ; domainInterestUsers . add ( new JsonObject ( ) . put ( "userId" , user . id ) . put ( "value" , domainValue ) ) ; beliefsAndValuesUsers . add ( new JsonObject ( ) . put ( "userId" , user . id ) . put ( "value" , beliefValue ) ) ; totals . add ( new JsonObject ( ) . put ( "userId" , user . id ) . put ( "value" , total ) ) ; } Collections . sort ( totals , ( a , b ) -> b . getDouble ( "value" ) . compareTo ( a . getDouble ( "value" ) ) ) ; for ( final var whoToAskUser : totals ) { whoToAskUsers . add ( whoToAskUser ) ; if ( whoToAskUsers . size ( ) > MAX_USERS ) { unaskedUserIds . add ( whoToAskUser . getString ( "userId" ) ) ; } } this . assertSuccessfulCompleted ( testContext ) ; }
Create the expected state.
Create the expected state .