<commit_before>// Copyright 2018 The Oppia Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview Validator service for the number with units interaction.
 */

require('domain/objects/NumberWithUnitsObjectFactory.ts');
require('interactions/baseInteractionValidationService.ts');

var oppia = require('AppInit.ts').module;

oppia.factory('NumberWithUnitsValidationService', [
  'NumberWithUnitsObjectFactory', 'baseInteractionValidationService',
  'WARNING_TYPES',
  function(NumberWithUnitsObjectFactory, baseInteractionValidationService,
      WARNING_TYPES) {
    return {
      getCustomizationArgsWarnings: function(customizationArgs) {
        return [];
      },
      getAllWarnings: function(
          stateName, customizationArgs, answerGroups, defaultOutcome) {
        var warningsList = [];

        warningsList = warningsList.concat(
          this.getCustomizationArgsWarnings(customizationArgs));

        try {
          NumberWithUnitsObjectFactory.createCurrencyUnits();
        } catch (parsingError) {}

        var checkEquality = function(earlierRule, laterRule) {
          var answer = NumberWithUnitsObjectFactory.fromDict(
            earlierRule.inputs.f);
          var inputs = NumberWithUnitsObjectFactory.fromDict(
            laterRule.inputs.f);

          var answerString = answer.toMathjsCompatibleString();
          var inputsString = inputs.toMathjsCompatibleString();

          var answerList = NumberWithUnitsObjectFactory.fromRawInputString(
            answerString).toDict();
          var inputsList = NumberWithUnitsObjectFactory.fromRawInputString(
            inputsString).toDict();
          return angular.equals(answerList, inputsList);
        };

        var checkEquivalency = function(earlierRule, laterRule) {
          var earlierInput = NumberWithUnitsObjectFactory.fromDict(
            earlierRule.inputs.f);
          var laterInput = NumberWithUnitsObjectFactory.fromDict(
            laterRule.inputs.f);
          if (earlierInput.type === 'fraction') {
            earlierInput.type = 'real';
            earlierInput.real = earlierInput.fraction.toFloat();
          }
          if (laterInput.type === 'fraction') {
            laterInput.type = 'real';
            laterInput.real = laterInput.fraction.toFloat();
          }
          var earlierInputString = earlierInput.toMathjsCompatibleString();
          var laterInputString = laterInput.toMathjsCompatibleString();
          return math.unit(laterInputString).equals(math.unit(
            earlierInputString));<commit_msg>Fix #7087: Add log for "contains no units" SyntaxError (#7157)<commit_after>// Copyright 2018 The Oppia Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview Validator service for the number with units interaction.
 */

require('domain/objects/NumberWithUnitsObjectFactory.ts');
require('interactions/baseInteractionValidationService.ts');

var oppia = require('AppInit.ts').module;

oppia.factory('NumberWithUnitsValidationService', [
  'NumberWithUnitsObjectFactory', 'baseInteractionValidationService',
  'WARNING_TYPES',
  function(NumberWithUnitsObjectFactory, baseInteractionValidationService,
      WARNING_TYPES) {
    return {
      getCustomizationArgsWarnings: function(customizationArgs) {
        return [];
      },
      getAllWarnings: function(
          stateName, customizationArgs, answerGroups, defaultOutcome) {
        var warningsList = [];

        warningsList = warningsList.concat(
          this.getCustomizationArgsWarnings(customizationArgs));

        try {
          NumberWithUnitsObjectFactory.createCurrencyUnits();
        } catch (parsingError) {}

        var checkEquality = function(earlierRule, laterRule) {
          var answer = NumberWithUnitsObjectFactory.fromDict(
            earlierRule.inputs.f);
          var inputs = NumberWithUnitsObjectFactory.fromDict(
            laterRule.inputs.f);

          var answerString = answer.toMathjsCompatibleString();
          var inputsString = inputs.toMathjsCompatibleString();

          var answerList = NumberWithUnitsObjectFactory.fromRawInputString(
            answerString).toDict();
          var inputsList = NumberWithUnitsObjectFactory.fromRawInputString(
            inputsString).toDict();
          return angular.equals(answerList, inputsList);
        };

        var checkEquivalency = function(earlierRule, laterRule) {
          var earlierInput = NumberWithUnitsObjectFactory.fromDict(
            earlierRule.inputs.f);
          var laterInput = NumberWithUnitsObjectFactory.fromDict(
            laterRule.inputs.f);
          if (earlierInput.type === 'fraction') {
            earlierInput.type = 'real';
            earlierInput.real = earlierInput.fraction.toFloat();
          }
          if (laterInput.type === 'fraction') {
            laterInput.type = 'real';
            laterInput.real = laterInput.fraction.toFloat();
          }
          var earlierInputString = earlierInput.toMathjsCompatibleString();
          var laterInputString = laterInput.toMathjsCompatibleString();
          try {
            return math.unit(laterInputString).equals(math.unit(
              earlierInputString));
          } catch (e) {
            var additionalInfo = (
              '\nlaterInput: ' + JSON.stringify(laterInput.toDict()) +
              '\nearlierInput: ' + JSON.stringify(earlierInput.toDict())
            );
            e.message += additionalInfo;
            throw e;
          }
{'fraction_non_alphanumeric': 0.09220720036457543, 'fraction_numerical': 0.0036457542154033117, 'mean_word_length': 2.8935541099940862, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5531781', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1649, 'n_words': 401}