Best JavaScript code snippet using storybook-root
data_utils.py
Source:data_utils.py  
1# Copyright 2016 Google Inc. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15"""Functions for constructing vocabulary, converting the examples to integer format and building the required masks for batch computation Author: aneelakantan (Arvind Neelakantan)16"""17import copy18import numbers19import numpy as np20import wiki_data21def return_index(a):22  for i in range(len(a)):23    if (a[i] == 1.0):24      return i25def construct_vocab(data, utility, add_word=False):26  ans = []27  for example in data:28    sent = ""29    for word in example.question:30      if (not (isinstance(word, numbers.Number))):31        sent += word + " "32    example.original_nc = copy.deepcopy(example.number_columns)33    example.original_wc = copy.deepcopy(example.word_columns)34    example.original_nc_names = copy.deepcopy(example.number_column_names)35    example.original_wc_names = copy.deepcopy(example.word_column_names)36    if (add_word):37      continue38    number_found = 039    if (not (example.is_bad_example)):40      for word in example.question:41        if (isinstance(word, numbers.Number)):42          number_found += 143        else:44          if (not (utility.word_ids.has_key(word))):45            utility.words.append(word)46            utility.word_count[word] = 147            utility.word_ids[word] = len(utility.word_ids)48            utility.reverse_word_ids[utility.word_ids[word]] = word49          else:50            utility.word_count[word] += 151      for col_name in example.word_column_names:52        for word in col_name:53          if (isinstance(word, numbers.Number)):54            number_found += 155          else:56            if (not (utility.word_ids.has_key(word))):57              utility.words.append(word)58              utility.word_count[word] = 159              utility.word_ids[word] = len(utility.word_ids)60              utility.reverse_word_ids[utility.word_ids[word]] = word61            else:62              utility.word_count[word] += 163      for col_name in example.number_column_names:64        for word in col_name:65          if (isinstance(word, numbers.Number)):66            number_found += 167          else:68            if (not (utility.word_ids.has_key(word))):69              utility.words.append(word)70              utility.word_count[word] = 171              utility.word_ids[word] = len(utility.word_ids)72              utility.reverse_word_ids[utility.word_ids[word]] = word73            else:74              utility.word_count[word] += 175def word_lookup(word, utility):76  if (utility.word_ids.has_key(word)):77    return word78  else:79    return utility.unk_token80def convert_to_int_2d_and_pad(a, utility):81  ans = []82  #print a83  for b in a:84    temp = []85    if (len(b) > utility.FLAGS.max_entry_length):86      b = b[0:utility.FLAGS.max_entry_length]87    for remaining in range(len(b), utility.FLAGS.max_entry_length):88      b.append(utility.dummy_token)89    assert len(b) == utility.FLAGS.max_entry_length90    for word in b:91      temp.append(utility.word_ids[word_lookup(word, utility)])92    ans.append(temp)93  #print ans94  return ans95def convert_to_bool_and_pad(a, utility):96  a = a.tolist()97  for i in range(len(a)):98    for j in range(len(a[i])):99      if (a[i][j] < 1):100        a[i][j] = False101      else:102        a[i][j] = True103    a[i] = a[i] + [False] * (utility.FLAGS.max_elements - len(a[i]))104  return a105seen_tables = {}106def partial_match(question, table, number):107  answer = []108  match = {}109  for i in range(len(table)):110    temp = []111    for j in range(len(table[i])):112      temp.append(0)113    answer.append(temp)114  for i in range(len(table)):115    for j in range(len(table[i])):116      for word in question:117        if (number):118          if (word == table[i][j]):119            answer[i][j] = 1.0120            match[i] = 1.0121        else:122          if (word in table[i][j]):123            answer[i][j] = 1.0124            match[i] = 1.0125  return answer, match126def exact_match(question, table, number):127  #performs exact match operation128  answer = []129  match = {}130  matched_indices = []131  for i in range(len(table)):132    temp = []133    for j in range(len(table[i])):134      temp.append(0)135    answer.append(temp)136  for i in range(len(table)):137    for j in range(len(table[i])):138      if (number):139        for word in question:140          if (word == table[i][j]):141            match[i] = 1.0142            answer[i][j] = 1.0143      else:144        table_entry = table[i][j]145        for k in range(len(question)):146          if (k + len(table_entry) <= len(question)):147            if (table_entry == question[k:(k + len(table_entry))]):148              #if(len(table_entry) == 1):149              #print "match: ", table_entry, question150              match[i] = 1.0151              answer[i][j] = 1.0152              matched_indices.append((k, len(table_entry)))153  return answer, match, matched_indices154def partial_column_match(question, table, number):155  answer = []156  for i in range(len(table)):157    answer.append(0)158  for i in range(len(table)):159    for word in question:160      if (word in table[i]):161        answer[i] = 1.0162  return answer163def exact_column_match(question, table, number):164  #performs exact match on column names165  answer = []166  matched_indices = []167  for i in range(len(table)):168    answer.append(0)169  for i in range(len(table)):170    table_entry = table[i]171    for k in range(len(question)):172      if (k + len(table_entry) <= len(question)):173        if (table_entry == question[k:(k + len(table_entry))]):174          answer[i] = 1.0175          matched_indices.append((k, len(table_entry)))176  return answer, matched_indices177def get_max_entry(a):178  e = {}179  for w in a:180    if (w != "UNK, "):181      if (e.has_key(w)):182        e[w] += 1183      else:184        e[w] = 1185  if (len(e) > 0):186    (key, val) = sorted(e.items(), key=lambda x: -1 * x[1])[0]187    if (val > 1):188      return key189    else:190      return -1.0191  else:192    return -1.0193def list_join(a):194  ans = ""195  for w in a:196    ans += str(w) + ", "197  return ans198def group_by_max(table, number):199  #computes the most frequently occuring entry in a column200  answer = []201  for i in range(len(table)):202    temp = []203    for j in range(len(table[i])):204      temp.append(0)205    answer.append(temp)206  for i in range(len(table)):207    if (number):208      curr = table[i]209    else:210      curr = [list_join(w) for w in table[i]]211    max_entry = get_max_entry(curr)212    #print i, max_entry213    for j in range(len(curr)):214      if (max_entry == curr[j]):215        answer[i][j] = 1.0216      else:217        answer[i][j] = 0.0218  return answer219def pick_one(a):220  for i in range(len(a)):221    if (1.0 in a[i]):222      return True223  return False224def check_processed_cols(col, utility):225  return True in [226      True for y in col227      if (y != utility.FLAGS.pad_int and y !=228          utility.FLAGS.bad_number_pre_process)229  ]230def complete_wiki_processing(data, utility, train=True):231  #convert to integers and padding232  processed_data = []233  num_bad_examples = 0234  for example in data:235    number_found = 0236    if (example.is_bad_example):237      num_bad_examples += 1238    if (not (example.is_bad_example)):239      example.string_question = example.question[:]240      #entry match241      example.processed_number_columns = example.processed_number_columns[:]242      example.processed_word_columns = example.processed_word_columns[:]243      example.word_exact_match, word_match, matched_indices = exact_match(244          example.string_question, example.original_wc, number=False)245      example.number_exact_match, number_match, _ = exact_match(246          example.string_question, example.original_nc, number=True)247      if (not (pick_one(example.word_exact_match)) and not (248          pick_one(example.number_exact_match))):249        assert len(word_match) == 0250        assert len(number_match) == 0251        example.word_exact_match, word_match = partial_match(252            example.string_question, example.original_wc, number=False)253      #group by max254      example.word_group_by_max = group_by_max(example.original_wc, False)255      example.number_group_by_max = group_by_max(example.original_nc, True)256      #column name match257      example.word_column_exact_match, wcol_matched_indices = exact_column_match(258          example.string_question, example.original_wc_names, number=False)259      example.number_column_exact_match, ncol_matched_indices = exact_column_match(260          example.string_question, example.original_nc_names, number=False)261      if (not (1.0 in example.word_column_exact_match) and not (262          1.0 in example.number_column_exact_match)):263        example.word_column_exact_match = partial_column_match(264            example.string_question, example.original_wc_names, number=False)265        example.number_column_exact_match = partial_column_match(266            example.string_question, example.original_nc_names, number=False)267      if (len(word_match) > 0 or len(number_match) > 0):268        example.question.append(utility.entry_match_token)269      if (1.0 in example.word_column_exact_match or270          1.0 in example.number_column_exact_match):271        example.question.append(utility.column_match_token)272      example.string_question = example.question[:]273      example.number_lookup_matrix = np.transpose(274          example.number_lookup_matrix)[:]275      example.word_lookup_matrix = np.transpose(example.word_lookup_matrix)[:]276      example.columns = example.number_columns[:]277      example.word_columns = example.word_columns[:]278      example.len_total_cols = len(example.word_column_names) + len(279          example.number_column_names)280      example.column_names = example.number_column_names[:]281      example.word_column_names = example.word_column_names[:]282      example.string_column_names = example.number_column_names[:]283      example.string_word_column_names = example.word_column_names[:]284      example.sorted_number_index = []285      example.sorted_word_index = []286      example.column_mask = []287      example.word_column_mask = []288      example.processed_column_mask = []289      example.processed_word_column_mask = []290      example.word_column_entry_mask = []291      example.question_attention_mask = []292      example.question_number = example.question_number_1 = -1293      example.question_attention_mask = []294      example.ordinal_question = []295      example.ordinal_question_one = []296      new_question = []297      if (len(example.number_columns) > 0):298        example.len_col = len(example.number_columns[0])299      else:300        example.len_col = len(example.word_columns[0])301      for (start, length) in matched_indices:302        for j in range(length):303          example.question[start + j] = utility.unk_token304      #print example.question305      for word in example.question:306        if (isinstance(word, numbers.Number) or wiki_data.is_date(word)):307          if (not (isinstance(word, numbers.Number)) and308              wiki_data.is_date(word)):309            word = word.replace("X", "").replace("-", "")310          number_found += 1311          if (number_found == 1):312            example.question_number = word313            if (len(example.ordinal_question) > 0):314              example.ordinal_question[len(example.ordinal_question) - 1] = 1.0315            else:316              example.ordinal_question.append(1.0)317          elif (number_found == 2):318            example.question_number_1 = word319            if (len(example.ordinal_question_one) > 0):320              example.ordinal_question_one[len(example.ordinal_question_one) -321                                           1] = 1.0322            else:323              example.ordinal_question_one.append(1.0)324        else:325          new_question.append(word)326          example.ordinal_question.append(0.0)327          example.ordinal_question_one.append(0.0)328      example.question = [329          utility.word_ids[word_lookup(w, utility)] for w in new_question330      ]331      example.question_attention_mask = [0.0] * len(example.question)332      #when the first question number occurs before a word333      example.ordinal_question = example.ordinal_question[0:len(334          example.question)]335      example.ordinal_question_one = example.ordinal_question_one[0:len(336          example.question)]337      #question-padding338      example.question = [utility.word_ids[utility.dummy_token]] * (339          utility.FLAGS.question_length - len(example.question)340      ) + example.question341      example.question_attention_mask = [-10000.0] * (342          utility.FLAGS.question_length - len(example.question_attention_mask)343      ) + example.question_attention_mask344      example.ordinal_question = [0.0] * (utility.FLAGS.question_length -345                                          len(example.ordinal_question)346                                         ) + example.ordinal_question347      example.ordinal_question_one = [0.0] * (utility.FLAGS.question_length -348                                              len(example.ordinal_question_one)349                                             ) + example.ordinal_question_one350      if (True):351        #number columns and related-padding352        num_cols = len(example.columns)353        start = 0354        for column in example.number_columns:355          if (check_processed_cols(example.processed_number_columns[start],356                                   utility)):357            example.processed_column_mask.append(0.0)358          sorted_index = sorted(359              range(len(example.processed_number_columns[start])),360              key=lambda k: example.processed_number_columns[start][k],361              reverse=True)362          sorted_index = sorted_index + [utility.FLAGS.pad_int] * (363              utility.FLAGS.max_elements - len(sorted_index))364          example.sorted_number_index.append(sorted_index)365          example.columns[start] = column + [utility.FLAGS.pad_int] * (366              utility.FLAGS.max_elements - len(column))367          example.processed_number_columns[start] += [utility.FLAGS.pad_int] * (368              utility.FLAGS.max_elements -369              len(example.processed_number_columns[start]))370          start += 1371          example.column_mask.append(0.0)372        for remaining in range(num_cols, utility.FLAGS.max_number_cols):373          example.sorted_number_index.append([utility.FLAGS.pad_int] *374                                             (utility.FLAGS.max_elements))375          example.columns.append([utility.FLAGS.pad_int] *376                                 (utility.FLAGS.max_elements))377          example.processed_number_columns.append([utility.FLAGS.pad_int] *378                                                  (utility.FLAGS.max_elements))379          example.number_exact_match.append([0.0] *380                                            (utility.FLAGS.max_elements))381          example.number_group_by_max.append([0.0] *382                                             (utility.FLAGS.max_elements))383          example.column_mask.append(-100000000.0)384          example.processed_column_mask.append(-100000000.0)385          example.number_column_exact_match.append(0.0)386          example.column_names.append([utility.dummy_token])387        #word column  and related-padding388        start = 0389        word_num_cols = len(example.word_columns)390        for column in example.word_columns:391          if (check_processed_cols(example.processed_word_columns[start],392                                   utility)):393            example.processed_word_column_mask.append(0.0)394          sorted_index = sorted(395              range(len(example.processed_word_columns[start])),396              key=lambda k: example.processed_word_columns[start][k],397              reverse=True)398          sorted_index = sorted_index + [utility.FLAGS.pad_int] * (399              utility.FLAGS.max_elements - len(sorted_index))400          example.sorted_word_index.append(sorted_index)401          column = convert_to_int_2d_and_pad(column, utility)402          example.word_columns[start] = column + [[403              utility.word_ids[utility.dummy_token]404          ] * utility.FLAGS.max_entry_length] * (utility.FLAGS.max_elements -405                                                 len(column))406          example.processed_word_columns[start] += [utility.FLAGS.pad_int] * (407              utility.FLAGS.max_elements -408              len(example.processed_word_columns[start]))409          example.word_column_entry_mask.append([0] * len(column) + [410              utility.word_ids[utility.dummy_token]411          ] * (utility.FLAGS.max_elements - len(column)))412          start += 1413          example.word_column_mask.append(0.0)414        for remaining in range(word_num_cols, utility.FLAGS.max_word_cols):415          example.sorted_word_index.append([utility.FLAGS.pad_int] *416                                           (utility.FLAGS.max_elements))417          example.word_columns.append([[utility.word_ids[utility.dummy_token]] *418                                       utility.FLAGS.max_entry_length] *419                                      (utility.FLAGS.max_elements))420          example.word_column_entry_mask.append(421              [utility.word_ids[utility.dummy_token]] *422              (utility.FLAGS.max_elements))423          example.word_exact_match.append([0.0] * (utility.FLAGS.max_elements))424          example.word_group_by_max.append([0.0] * (utility.FLAGS.max_elements))425          example.processed_word_columns.append([utility.FLAGS.pad_int] *426                                                (utility.FLAGS.max_elements))427          example.word_column_mask.append(-100000000.0)428          example.processed_word_column_mask.append(-100000000.0)429          example.word_column_exact_match.append(0.0)430          example.word_column_names.append([utility.dummy_token] *431                                           utility.FLAGS.max_entry_length)432        seen_tables[example.table_key] = 1433      #convert column and word column names to integers434      example.column_ids = convert_to_int_2d_and_pad(example.column_names,435                                                     utility)436      example.word_column_ids = convert_to_int_2d_and_pad(437          example.word_column_names, utility)438      for i_em in range(len(example.number_exact_match)):439        example.number_exact_match[i_em] = example.number_exact_match[440            i_em] + [0.0] * (utility.FLAGS.max_elements -441                             len(example.number_exact_match[i_em]))442        example.number_group_by_max[i_em] = example.number_group_by_max[443            i_em] + [0.0] * (utility.FLAGS.max_elements -444                             len(example.number_group_by_max[i_em]))445      for i_em in range(len(example.word_exact_match)):446        example.word_exact_match[i_em] = example.word_exact_match[447            i_em] + [0.0] * (utility.FLAGS.max_elements -448                             len(example.word_exact_match[i_em]))449        example.word_group_by_max[i_em] = example.word_group_by_max[450            i_em] + [0.0] * (utility.FLAGS.max_elements -451                             len(example.word_group_by_max[i_em]))452      example.exact_match = example.number_exact_match + example.word_exact_match453      example.group_by_max = example.number_group_by_max + example.word_group_by_max454      example.exact_column_match = example.number_column_exact_match + example.word_column_exact_match455      #answer and related mask, padding456      if (example.is_lookup):457        example.answer = example.calc_answer458        example.number_print_answer = example.number_lookup_matrix.tolist()459        example.word_print_answer = example.word_lookup_matrix.tolist()460        for i_answer in range(len(example.number_print_answer)):461          example.number_print_answer[i_answer] = example.number_print_answer[462              i_answer] + [0.0] * (utility.FLAGS.max_elements -463                                   len(example.number_print_answer[i_answer]))464        for i_answer in range(len(example.word_print_answer)):465          example.word_print_answer[i_answer] = example.word_print_answer[466              i_answer] + [0.0] * (utility.FLAGS.max_elements -467                                   len(example.word_print_answer[i_answer]))468        example.number_lookup_matrix = convert_to_bool_and_pad(469            example.number_lookup_matrix, utility)470        example.word_lookup_matrix = convert_to_bool_and_pad(471            example.word_lookup_matrix, utility)472        for remaining in range(num_cols, utility.FLAGS.max_number_cols):473          example.number_lookup_matrix.append([False] *474                                              utility.FLAGS.max_elements)475          example.number_print_answer.append([0.0] * utility.FLAGS.max_elements)476        for remaining in range(word_num_cols, utility.FLAGS.max_word_cols):477          example.word_lookup_matrix.append([False] *478                                            utility.FLAGS.max_elements)479          example.word_print_answer.append([0.0] * utility.FLAGS.max_elements)480        example.print_answer = example.number_print_answer + example.word_print_answer481      else:482        example.answer = example.calc_answer483        example.print_answer = [[0.0] * (utility.FLAGS.max_elements)] * (484            utility.FLAGS.max_number_cols + utility.FLAGS.max_word_cols)485      #question_number masks486      if (example.question_number == -1):487        example.question_number_mask = np.zeros([utility.FLAGS.max_elements])488      else:489        example.question_number_mask = np.ones([utility.FLAGS.max_elements])490      if (example.question_number_1 == -1):491        example.question_number_one_mask = -10000.0492      else:493        example.question_number_one_mask = np.float64(0.0)494      if (example.len_col > utility.FLAGS.max_elements):495        continue496      processed_data.append(example)497  return processed_data498def add_special_words(utility):499  utility.words.append(utility.entry_match_token)500  utility.word_ids[utility.entry_match_token] = len(utility.word_ids)501  utility.reverse_word_ids[utility.word_ids[502      utility.entry_match_token]] = utility.entry_match_token503  utility.entry_match_token_id = utility.word_ids[utility.entry_match_token]504  print "entry match token: ", utility.word_ids[505      utility.entry_match_token], utility.entry_match_token_id506  utility.words.append(utility.column_match_token)507  utility.word_ids[utility.column_match_token] = len(utility.word_ids)508  utility.reverse_word_ids[utility.word_ids[509      utility.column_match_token]] = utility.column_match_token510  utility.column_match_token_id = utility.word_ids[utility.column_match_token]511  print "entry match token: ", utility.word_ids[512      utility.column_match_token], utility.column_match_token_id513  utility.words.append(utility.dummy_token)514  utility.word_ids[utility.dummy_token] = len(utility.word_ids)515  utility.reverse_word_ids[utility.word_ids[516      utility.dummy_token]] = utility.dummy_token517  utility.dummy_token_id = utility.word_ids[utility.dummy_token]518  utility.words.append(utility.unk_token)519  utility.word_ids[utility.unk_token] = len(utility.word_ids)520  utility.reverse_word_ids[utility.word_ids[521      utility.unk_token]] = utility.unk_token522def perform_word_cutoff(utility):523  if (utility.FLAGS.word_cutoff > 0):524    for word in utility.word_ids.keys():525      if (utility.word_count.has_key(word) and utility.word_count[word] <526          utility.FLAGS.word_cutoff and word != utility.unk_token and527          word != utility.dummy_token and word != utility.entry_match_token and528          word != utility.column_match_token):529        utility.word_ids.pop(word)530        utility.words.remove(word)531def word_dropout(question, utility):532  if (utility.FLAGS.word_dropout_prob > 0.0):533    new_question = []534    for i in range(len(question)):535      if (question[i] != utility.dummy_token_id and536          utility.random.random() > utility.FLAGS.word_dropout_prob):537        new_question.append(utility.word_ids[utility.unk_token])538      else:539        new_question.append(question[i])540    return new_question541  else:542    return question543def generate_feed_dict(data, curr, batch_size, gr, train=False, utility=None):544  #prepare feed dict dictionary545  feed_dict = {}546  feed_examples = []547  for j in range(batch_size):548    feed_examples.append(data[curr + j])549  if (train):550    feed_dict[gr.batch_question] = [551        word_dropout(feed_examples[j].question, utility)552        for j in range(batch_size)553    ]554  else:555    feed_dict[gr.batch_question] = [556        feed_examples[j].question for j in range(batch_size)557    ]558  feed_dict[gr.batch_question_attention_mask] = [559      feed_examples[j].question_attention_mask for j in range(batch_size)560  ]561  feed_dict[562      gr.batch_answer] = [feed_examples[j].answer for j in range(batch_size)]563  feed_dict[gr.batch_number_column] = [564      feed_examples[j].columns for j in range(batch_size)565  ]566  feed_dict[gr.batch_processed_number_column] = [567      feed_examples[j].processed_number_columns for j in range(batch_size)568  ]569  feed_dict[gr.batch_processed_sorted_index_number_column] = [570      feed_examples[j].sorted_number_index for j in range(batch_size)571  ]572  feed_dict[gr.batch_processed_sorted_index_word_column] = [573      feed_examples[j].sorted_word_index for j in range(batch_size)574  ]575  feed_dict[gr.batch_question_number] = np.array(576      [feed_examples[j].question_number for j in range(batch_size)]).reshape(577          (batch_size, 1))578  feed_dict[gr.batch_question_number_one] = np.array(579      [feed_examples[j].question_number_1 for j in range(batch_size)]).reshape(580          (batch_size, 1))581  feed_dict[gr.batch_question_number_mask] = [582      feed_examples[j].question_number_mask for j in range(batch_size)583  ]584  feed_dict[gr.batch_question_number_one_mask] = np.array(585      [feed_examples[j].question_number_one_mask for j in range(batch_size)586      ]).reshape((batch_size, 1))587  feed_dict[gr.batch_print_answer] = [588      feed_examples[j].print_answer for j in range(batch_size)589  ]590  feed_dict[gr.batch_exact_match] = [591      feed_examples[j].exact_match for j in range(batch_size)592  ]593  feed_dict[gr.batch_group_by_max] = [594      feed_examples[j].group_by_max for j in range(batch_size)595  ]596  feed_dict[gr.batch_column_exact_match] = [597      feed_examples[j].exact_column_match for j in range(batch_size)598  ]599  feed_dict[gr.batch_ordinal_question] = [600      feed_examples[j].ordinal_question for j in range(batch_size)601  ]602  feed_dict[gr.batch_ordinal_question_one] = [603      feed_examples[j].ordinal_question_one for j in range(batch_size)604  ]605  feed_dict[gr.batch_number_column_mask] = [606      feed_examples[j].column_mask for j in range(batch_size)607  ]608  feed_dict[gr.batch_number_column_names] = [609      feed_examples[j].column_ids for j in range(batch_size)610  ]611  feed_dict[gr.batch_processed_word_column] = [612      feed_examples[j].processed_word_columns for j in range(batch_size)613  ]614  feed_dict[gr.batch_word_column_mask] = [615      feed_examples[j].word_column_mask for j in range(batch_size)616  ]617  feed_dict[gr.batch_word_column_names] = [618      feed_examples[j].word_column_ids for j in range(batch_size)619  ]620  feed_dict[gr.batch_word_column_entry_mask] = [621      feed_examples[j].word_column_entry_mask for j in range(batch_size)622  ]...media_sequence_util_test.py
Source:media_sequence_util_test.py  
...45    "int64_list_feature_list", "int64_list_feature_list",46    module_dict=msu.__dict__)47class MediaSequenceTest(tf.test.TestCase):48  def test_set_context_float(self):49    example = tf.train.SequenceExample()50    key = "test_float"51    msu.set_context_float(key, 0.1, example)52    self.assertAlmostEqual(0.1,53                           example.context.feature[key].float_list.value[0])54  def test_set_context_bytes(self):55    example = tf.train.SequenceExample()56    key = "test_string"57    msu.set_context_bytes(key, b"test", example)58    self.assertEqual(b"test",59                     example.context.feature[key].bytes_list.value[0])60  def test_set_context_int(self):61    example = tf.train.SequenceExample()62    key = "test_int"63    msu.set_context_int(key, 47, example)64    self.assertEqual(47,65                     example.context.feature[key].int64_list.value[0])66  def test_set_context_float_list(self):67    example = tf.train.SequenceExample()68    key = "test_float_list"69    msu.set_context_float_list(key, [0.0, 0.1], example)70    self.assertSequenceAlmostEqual(71        [0.0, 0.1], example.context.feature[key].float_list.value)72  def test_set_context_bytes_list(self):73    example = tf.train.SequenceExample()74    key = "test_string_list"75    msu.set_context_bytes_list(key, [b"test", b"test"], example)76    self.assertSequenceAlmostEqual(77        [b"test", b"test"], example.context.feature[key].bytes_list.value)78  def test_set_context_int_list(self):79    example = tf.train.SequenceExample()80    key = "test_int_list"81    msu.set_context_int_list(key, [0, 1], example)82    self.assertSequenceAlmostEqual(83        [0, 1], example.context.feature[key].int64_list.value)84  def test_round_trip_float_list_feature(self):85    example = tf.train.SequenceExample()86    key = "test_float_features"87    msu.add_float_list(key, [0.0, 0.1], example)88    msu.add_float_list(key, [0.1, 0.2], example)89    self.assertEqual(2, msu.get_feature_list_size(key, example))90    self.assertTrue(msu.has_feature_list(key, example))91    self.assertAllClose([0.0, 0.1], msu.get_float_list_at(key, 0, example))92    self.assertAllClose([0.1, 0.2], msu.get_float_list_at(key, 1, example))93    msu.clear_feature_list(key, example)94    self.assertEqual(0, msu.get_feature_list_size(key, example))95    self.assertFalse(msu.has_feature_list(key, example))96  def test_round_trip_bytes_list_feature(self):97    example = tf.train.SequenceExample()98    key = "test_bytes_features"99    msu.add_bytes_list(key, [b"test0", b"test1"], example)100    msu.add_bytes_list(key, [b"test1", b"test2"], example)101    self.assertEqual(2, msu.get_feature_list_size(key, example))102    self.assertTrue(msu.has_feature_list(key, example))103    self.assertAllEqual([b"test0", b"test1"],104                        msu.get_bytes_list_at(key, 0, example))105    self.assertAllEqual([b"test1", b"test2"],106                        msu.get_bytes_list_at(key, 1, example))107    msu.clear_feature_list(key, example)108    self.assertEqual(0, msu.get_feature_list_size(key, example))109    self.assertFalse(msu.has_feature_list(key, example))110  def test_round_trip_int_list_feature(self):111    example = tf.train.SequenceExample()112    key = "test_ints_features"113    msu.add_int_list(key, [0, 1], example)114    msu.add_int_list(key, [1, 2], example)115    self.assertEqual(2, msu.get_feature_list_size(key, example))116    self.assertTrue(msu.has_feature_list(key, example))117    self.assertAllClose([0, 1], msu.get_int_list_at(key, 0, example))118    self.assertAllClose([1, 2], msu.get_int_list_at(key, 1, example))119    msu.clear_feature_list(key, example)120    self.assertEqual(0, msu.get_feature_list_size(key, example))121    self.assertFalse(msu.has_feature_list(key, example))122  def test_round_trip_string_context(self):123    example = tf.train.SequenceExample()124    key = "string_feature"125    msu.set_string_context(b"test", example)126    self.assertEqual(b"test", msu.get_string_context(example))127    self.assertTrue(msu.has_string_context(example))128    self.assertEqual(b"test",129                     example.context.feature[key].bytes_list.value[0])130    msu.clear_string_context(example)131    self.assertFalse(msu.has_string_context(example))132    self.assertEqual("string_feature", msu.get_string_context_key())133  def test_round_trip_float_context(self):134    example = tf.train.SequenceExample()135    key = "float_feature"136    msu.set_float_context(0.47, example)137    self.assertAlmostEqual(0.47, msu.get_float_context(example))138    self.assertTrue(msu.has_float_context(example))139    self.assertAlmostEqual(0.47,140                           example.context.feature[key].float_list.value[0])141    msu.clear_float_context(example)142    self.assertFalse(msu.has_float_context(example))143    self.assertEqual("float_feature", msu.get_float_context_key())144  def test_round_trip_int_context(self):145    example = tf.train.SequenceExample()146    key = "int64_feature"147    msu.set_int64_context(47, example)148    self.assertEqual(47, msu.get_int64_context(example))149    self.assertTrue(msu.has_int64_context(example))150    self.assertEqual(47,151                     example.context.feature[key].int64_list.value[0])152    msu.clear_int64_context(example)153    self.assertFalse(msu.has_int64_context(example))154    self.assertEqual("int64_feature", msu.get_int64_context_key())155  def test_round_trip_string_list_context(self):156    example = tf.train.SequenceExample()157    msu.set_string_list_context([b"test0", b"test1"], example)158    self.assertSequenceEqual([b"test0", b"test1"],159                             msu.get_string_list_context(example))160    self.assertTrue(msu.has_string_list_context(example))161    msu.clear_string_list_context(example)162    self.assertFalse(msu.has_string_list_context(example))163    self.assertEqual("string_vector_feature",164                     msu.get_string_list_context_key())165  def test_round_trip_float_list_context(self):166    example = tf.train.SequenceExample()167    msu.set_float_list_context([0.47, 0.49], example)168    self.assertSequenceAlmostEqual([0.47, 0.49],169                                   msu.get_float_list_context(example))170    self.assertTrue(msu.has_float_list_context(example))171    msu.clear_float_list_context(example)172    self.assertFalse(msu.has_float_list_context(example))173    self.assertEqual("float_vector_feature", msu.get_float_list_context_key())174  def test_round_trip_int_list_context(self):175    example = tf.train.SequenceExample()176    msu.set_int64_list_context([47, 49], example)177    self.assertSequenceEqual([47, 49], msu.get_int64_list_context(example))178    self.assertTrue(msu.has_int64_list_context(example))179    msu.clear_int64_list_context(example)180    self.assertFalse(msu.has_int64_list_context(example))181    self.assertEqual("int64_vector_feature", msu.get_int64_list_context_key())182  def test_round_trip_string_feature_list(self):183    example = tf.train.SequenceExample()184    msu.add_string_feature_list(b"test0", example)185    msu.add_string_feature_list(b"test1", example)186    self.assertEqual(b"test0", msu.get_string_feature_list_at(0, example))187    self.assertEqual(b"test1", msu.get_string_feature_list_at(1, example))188    self.assertTrue(msu.has_string_feature_list(example))189    self.assertEqual(2, msu.get_string_feature_list_size(example))190    msu.clear_string_feature_list(example)191    self.assertFalse(msu.has_string_feature_list(example))192    self.assertEqual(0, msu.get_string_feature_list_size(example))193    self.assertEqual("string_feature_list", msu.get_string_feature_list_key())194  def test_round_trip_float_feature_list(self):195    example = tf.train.SequenceExample()196    msu.add_float_feature_list(0.47, example)197    msu.add_float_feature_list(0.49, example)198    self.assertAlmostEqual(0.47, msu.get_float_feature_list_at(0, example))199    self.assertAlmostEqual(0.49, msu.get_float_feature_list_at(1, example))200    self.assertTrue(msu.has_float_feature_list(example))201    self.assertEqual(2, msu.get_float_feature_list_size(example))202    msu.clear_float_feature_list(example)203    self.assertFalse(msu.has_float_feature_list(example))204    self.assertEqual(0, msu.get_float_feature_list_size(example))205    self.assertEqual("float_feature_list", msu.get_float_feature_list_key())206  def test_round_trip_int_feature_list(self):207    example = tf.train.SequenceExample()208    msu.add_int64_feature_list(47, example)209    msu.add_int64_feature_list(49, example)210    self.assertEqual(47, msu.get_int64_feature_list_at(0, example))211    self.assertEqual(49, msu.get_int64_feature_list_at(1, example))212    self.assertTrue(msu.has_int64_feature_list(example))213    self.assertEqual(2, msu.get_int64_feature_list_size(example))214    msu.clear_int64_feature_list(example)215    self.assertFalse(msu.has_int64_feature_list(example))216    self.assertEqual(0, msu.get_int64_feature_list_size(example))217    self.assertEqual("int64_feature_list", msu.get_int64_feature_list_key())218  def test_round_trip_string_list_feature_list(self):219    example = tf.train.SequenceExample()220    msu.add_string_list_feature_list([b"test0", b"test1"], example)221    msu.add_string_list_feature_list([b"test1", b"test2"], example)222    self.assertSequenceEqual([b"test0", b"test1"],223                             msu.get_string_list_feature_list_at(0, example))224    self.assertSequenceEqual([b"test1", b"test2"],225                             msu.get_string_list_feature_list_at(1, example))226    self.assertTrue(msu.has_string_list_feature_list(example))227    self.assertEqual(2, msu.get_string_list_feature_list_size(example))228    msu.clear_string_list_feature_list(example)229    self.assertFalse(msu.has_string_list_feature_list(example))230    self.assertEqual(0, msu.get_string_list_feature_list_size(example))231    self.assertEqual("string_list_feature_list",232                     msu.get_string_list_feature_list_key())233  def test_round_trip_float_list_feature_list(self):234    example = tf.train.SequenceExample()235    msu.add_float_list_feature_list([0.47, 0.49], example)236    msu.add_float_list_feature_list([0.49, 0.50], example)237    self.assertSequenceAlmostEqual(238        [0.47, 0.49], msu.get_float_list_feature_list_at(0, example))239    self.assertSequenceAlmostEqual(240        [0.49, 0.50], msu.get_float_list_feature_list_at(1, example))241    self.assertTrue(msu.has_float_list_feature_list(example))242    self.assertEqual(2, msu.get_float_list_feature_list_size(example))243    msu.clear_float_list_feature_list(example)244    self.assertFalse(msu.has_float_list_feature_list(example))245    self.assertEqual(0, msu.get_float_list_feature_list_size(example))246    self.assertEqual("float_list_feature_list",247                     msu.get_float_list_feature_list_key())248  def test_round_trip_int_list_feature_list(self):249    example = tf.train.SequenceExample()250    msu.add_int64_list_feature_list([47, 49], example)251    msu.add_int64_list_feature_list([49, 50], example)252    self.assertSequenceEqual(253        [47, 49], msu.get_int64_list_feature_list_at(0, example))254    self.assertSequenceEqual(255        [49, 50], msu.get_int64_list_feature_list_at(1, example))256    self.assertTrue(msu.has_int64_list_feature_list(example))257    self.assertEqual(2, msu.get_int64_list_feature_list_size(example))258    msu.clear_int64_list_feature_list(example)259    self.assertFalse(msu.has_int64_list_feature_list(example))260    self.assertEqual(0, msu.get_int64_list_feature_list_size(example))261    self.assertEqual("int64_list_feature_list",262                     msu.get_int64_list_feature_list_key())263  def test_prefix_int64_context(self):264    example = tf.train.SequenceExample()265    msu.set_int64_context(47, example, prefix="magic")266    self.assertFalse(msu.has_int64_context(example))267    self.assertTrue(msu.has_int64_context(example, prefix="magic"))268    self.assertEqual(47, msu.get_int64_context(example, prefix="magic"))269  def test_prefix_float_context(self):270    example = tf.train.SequenceExample()271    msu.set_float_context(47., example, prefix="magic")272    self.assertFalse(msu.has_float_context(example))273    self.assertTrue(msu.has_float_context(example, prefix="magic"))274    self.assertAlmostEqual(47., msu.get_float_context(example, prefix="magic"))275  def test_prefix_string_context(self):276    example = tf.train.SequenceExample()277    msu.set_string_context(b"47", example, prefix="magic")278    self.assertFalse(msu.has_string_context(example))279    self.assertTrue(msu.has_string_context(example, prefix="magic"))280    self.assertEqual(b"47", msu.get_string_context(example, prefix="magic"))281  def test_prefix_int64_list_context(self):282    example = tf.train.SequenceExample()283    msu.set_int64_list_context((47,), example, prefix="magic")284    self.assertFalse(msu.has_int64_list_context(example))285    self.assertTrue(msu.has_int64_list_context(example, prefix="magic"))286    self.assertEqual([47,], msu.get_int64_list_context(example, prefix="magic"))287  def test_prefix_float_list_context(self):288    example = tf.train.SequenceExample()289    msu.set_float_list_context((47.,), example, prefix="magic")290    self.assertFalse(msu.has_float_list_context(example))291    self.assertTrue(msu.has_float_list_context(example, prefix="magic"))292    self.assertAlmostEqual([47.,],293                           msu.get_float_list_context(example, prefix="magic"))294  def test_prefix_string_list_context(self):295    example = tf.train.SequenceExample()296    msu.set_string_list_context((b"47",), example, prefix="magic")297    self.assertFalse(msu.has_string_list_context(example))298    self.assertTrue(msu.has_string_list_context(example, prefix="magic"))299    self.assertEqual([b"47",],300                     msu.get_string_list_context(example, prefix="magic"))301  def test_prefix_int64_feature_list(self):302    example = tf.train.SequenceExample()303    msu.add_int64_feature_list(47, example, prefix="magic")304    self.assertFalse(msu.has_int64_feature_list(example))305    self.assertTrue(msu.has_int64_feature_list(example, prefix="magic"))306    self.assertEqual(47,307                     msu.get_int64_feature_list_at(0, example, prefix="magic"))308  def test_prefix_float_feature_list(self):309    example = tf.train.SequenceExample()310    msu.add_float_feature_list(47., example, prefix="magic")311    self.assertFalse(msu.has_float_feature_list(example))312    self.assertTrue(msu.has_float_feature_list(example, prefix="magic"))313    self.assertAlmostEqual(314        47., msu.get_float_feature_list_at(0, example, prefix="magic"))315  def test_prefix_string_feature_list(self):316    example = tf.train.SequenceExample()317    msu.add_string_feature_list(b"47", example, prefix="magic")318    self.assertFalse(msu.has_string_feature_list(example))319    self.assertTrue(msu.has_string_feature_list(example, prefix="magic"))320    self.assertEqual(321        b"47", msu.get_string_feature_list_at(0, example, prefix="magic"))322  def test_prefix_int64_list_feature_list(self):323    example = tf.train.SequenceExample()324    msu.add_int64_list_feature_list((47,), example, prefix="magic")325    self.assertFalse(msu.has_int64_list_feature_list(example))326    self.assertTrue(msu.has_int64_list_feature_list(example, prefix="magic"))327    self.assertEqual(328        [47,], msu.get_int64_list_feature_list_at(0, example, prefix="magic"))329  def test_prefix_float_list_feature_list(self):330    example = tf.train.SequenceExample()331    msu.add_float_list_feature_list((47.,), example, prefix="magic")332    self.assertFalse(msu.has_float_list_feature_list(example))333    self.assertTrue(msu.has_float_list_feature_list(example, prefix="magic"))334    self.assertAlmostEqual(335        [47.,], msu.get_float_list_feature_list_at(0, example, prefix="magic"))336  def test_prefix_string_list_feature_list(self):337    example = tf.train.SequenceExample()338    msu.add_string_list_feature_list((b"47",), example, prefix="magic")339    self.assertFalse(msu.has_string_list_feature_list(example))340    self.assertTrue(msu.has_string_list_feature_list(example, prefix="magic"))341    self.assertEqual(342        [b"47",],343        msu.get_string_list_feature_list_at(0, example, prefix="magic"))344if __name__ == "__main__":...media_sequence_test.py
Source:media_sequence_test.py  
...22    # that we actually generate the expected methods. We only test one per23    # feature and the only test is to not crash with undefined attributes. By24    # passing in a value, we also ensure that the types are correct because the25    # underlying code crashes with a type mismatch.26    example = tf.train.SequenceExample()27    # context28    ms.set_example_id(b"string", example)29    ms.set_example_dataset_name(b"string", example)30    ms.set_clip_media_id(b"string", example)31    ms.set_clip_alternative_media_id(b"string", example)32    ms.set_clip_encoded_media_bytes(b"string", example)33    ms.set_clip_encoded_media_start_timestamp(47, example)34    ms.set_clip_data_path(b"string", example)35    ms.set_clip_start_timestamp(47, example)36    ms.set_clip_end_timestamp(47, example)37    ms.set_clip_label_string((b"string", b"test"), example)38    ms.set_clip_label_index((47, 49), example)39    ms.set_clip_label_confidence((0.47, 0.49), example)40    ms.set_segment_start_timestamp((47, 49), example)41    ms.set_segment_start_index((47, 49), example)42    ms.set_segment_end_timestamp((47, 49), example)43    ms.set_segment_end_index((47, 49), example)44    ms.set_segment_label_index((47, 49), example)45    ms.set_segment_label_string((b"test", b"strings"), example)46    ms.set_segment_label_confidence((0.47, 0.49), example)47    ms.set_image_format(b"test", example)48    ms.set_image_channels(47, example)49    ms.set_image_colorspace(b"test", example)50    ms.set_image_height(47, example)51    ms.set_image_width(47, example)52    ms.set_image_frame_rate(0.47, example)53    ms.set_image_data_path(b"test", example)54    ms.set_forward_flow_format(b"test", example)55    ms.set_forward_flow_channels(47, example)56    ms.set_forward_flow_colorspace(b"test", example)57    ms.set_forward_flow_height(47, example)58    ms.set_forward_flow_width(47, example)59    ms.set_forward_flow_frame_rate(0.47, example)60    ms.set_class_segmentation_format(b"test", example)61    ms.set_class_segmentation_height(47, example)62    ms.set_class_segmentation_width(47, example)63    ms.set_class_segmentation_class_label_string((b"test", b"strings"), example)64    ms.set_class_segmentation_class_label_index((47, 49), example)65    ms.set_instance_segmentation_format(b"test", example)66    ms.set_instance_segmentation_height(47, example)67    ms.set_instance_segmentation_width(47, example)68    ms.set_instance_segmentation_object_class_index((47, 49), example)69    ms.set_bbox_parts((b"HEAD", b"TOE"), example)70    # feature lists71    ms.add_image_encoded(b"test", example)72    ms.add_image_multi_encoded([b"test", b"test"], example)73    ms.add_image_timestamp(47, example)74    ms.add_forward_flow_encoded(b"test", example)75    ms.add_forward_flow_multi_encoded([b"test", b"test"], example)76    ms.add_forward_flow_timestamp(47, example)77    ms.add_bbox_ymin((0.47, 0.49), example)78    ms.add_bbox_xmin((0.47, 0.49), example)79    ms.add_bbox_ymax((0.47, 0.49), example)80    ms.add_bbox_xmax((0.47, 0.49), example)81    ms.add_bbox_point_x((0.47, 0.49), example)82    ms.add_bbox_point_y((0.47, 0.49), example)83    ms.add_bbox_3d_point_x((0.47, 0.49), example)84    ms.add_bbox_3d_point_y((0.47, 0.49), example)85    ms.add_bbox_3d_point_z((0.47, 0.49), example)86    ms.add_predicted_bbox_ymin((0.47, 0.49), example)87    ms.add_predicted_bbox_xmin((0.47, 0.49), example)88    ms.add_predicted_bbox_ymax((0.47, 0.49), example)89    ms.add_predicted_bbox_xmax((0.47, 0.49), example)90    ms.add_bbox_num_regions(47, example)91    ms.add_bbox_is_annotated(47, example)92    ms.add_bbox_is_generated((47, 49), example)93    ms.add_bbox_is_occluded((47, 49), example)94    ms.add_bbox_label_index((47, 49), example)95    ms.add_bbox_label_string((b"test", b"strings"), example)96    ms.add_bbox_label_confidence((0.47, 0.49), example)97    ms.add_bbox_class_index((47, 49), example)98    ms.add_bbox_class_string((b"test", b"strings"), example)99    ms.add_bbox_class_confidence((0.47, 0.49), example)100    ms.add_bbox_track_index((47, 49), example)101    ms.add_bbox_track_string((b"test", b"strings"), example)102    ms.add_bbox_track_confidence((0.47, 0.49), example)103    ms.add_bbox_timestamp(47, example)104    ms.add_predicted_bbox_class_index((47, 49), example)105    ms.add_predicted_bbox_class_string((b"test", b"strings"), example)106    ms.add_predicted_bbox_timestamp(47, example)107    ms.add_class_segmentation_encoded(b"test", example)108    ms.add_class_segmentation_multi_encoded([b"test", b"test"], example)109    ms.add_instance_segmentation_encoded(b"test", example)110    ms.add_instance_segmentation_multi_encoded([b"test", b"test"], example)111    ms.add_class_segmentation_timestamp(47, example)112    ms.set_bbox_embedding_dimensions_per_region((47, 49), example)113    ms.set_bbox_embedding_format(b"test", example)114    ms.add_bbox_embedding_floats((0.47, 0.49), example)115    ms.add_bbox_embedding_encoded((b"text", b"stings"), example)116    ms.add_bbox_embedding_confidence((0.47, 0.49), example)117    ms.set_text_language(b"test", example)118    ms.set_text_context_content(b"text", example)119    ms.add_text_content(b"one", example)120    ms.add_text_timestamp(47, example)121    ms.add_text_confidence(0.47, example)122    ms.add_text_duration(47, example)123    ms.add_text_token_id(47, example)124    ms.add_text_embedding((0.47, 0.49), example)125  def test_bbox_round_trip(self):126    example = tf.train.SequenceExample()127    boxes = np.array([[0.1, 0.2, 0.3, 0.4],128                      [0.5, 0.6, 0.7, 0.8]])129    empty_boxes = np.array([])130    ms.add_bbox(boxes, example)131    ms.add_bbox(empty_boxes, example)132    self.assertEqual(2, ms.get_bbox_size(example))133    self.assertAllClose(boxes, ms.get_bbox_at(0, example))134    self.assertTrue(ms.has_bbox(example))135    ms.clear_bbox(example)136    self.assertEqual(0, ms.get_bbox_size(example))137  def test_point_round_trip(self):138    example = tf.train.SequenceExample()139    points = np.array([[0.1, 0.2],140                       [0.5, 0.6]])141    ms.add_bbox_point(points, example)142    ms.add_bbox_point(points, example)143    self.assertEqual(2, ms.get_bbox_point_size(example))144    self.assertAllClose(points, ms.get_bbox_point_at(0, example))145    self.assertTrue(ms.has_bbox_point(example))146    ms.clear_bbox_point(example)147    self.assertEqual(0, ms.get_bbox_point_size(example))148  def test_prefixed_point_round_trip(self):149    example = tf.train.SequenceExample()150    points = np.array([[0.1, 0.2],151                       [0.5, 0.6]])152    ms.add_bbox_point(points, example, "test")153    ms.add_bbox_point(points, example, "test")154    self.assertEqual(2, ms.get_bbox_point_size(example, "test"))155    self.assertAllClose(points, ms.get_bbox_point_at(0, example, "test"))156    self.assertTrue(ms.has_bbox_point(example, "test"))157    ms.clear_bbox_point(example, "test")158    self.assertEqual(0, ms.get_bbox_point_size(example, "test"))159  def test_3d_point_round_trip(self):160    example = tf.train.SequenceExample()161    points = np.array([[0.1, 0.2, 0.3],162                       [0.5, 0.6, 0.7]])163    ms.add_bbox_3d_point(points, example)164    ms.add_bbox_3d_point(points, example)165    self.assertEqual(2, ms.get_bbox_3d_point_size(example))166    self.assertAllClose(points, ms.get_bbox_3d_point_at(0, example))167    self.assertTrue(ms.has_bbox_3d_point(example))168    ms.clear_bbox_3d_point(example)169    self.assertEqual(0, ms.get_bbox_3d_point_size(example))170  def test_predicted_bbox_round_trip(self):171    example = tf.train.SequenceExample()172    boxes = np.array([[0.1, 0.2, 0.3, 0.4],173                      [0.5, 0.6, 0.7, 0.8]])174    ms.add_predicted_bbox(boxes, example)175    ms.add_predicted_bbox(boxes, example)176    self.assertEqual(2, ms.get_predicted_bbox_size(example))177    self.assertAllClose(boxes, ms.get_predicted_bbox_at(0, example))178    self.assertTrue(ms.has_predicted_bbox(example))179    ms.clear_predicted_bbox(example)180    self.assertEqual(0, ms.get_predicted_bbox_size(example))181  def test_float_list_round_trip(self):182    example = tf.train.SequenceExample()183    values_1 = [0.1, 0.2, 0.3]184    values_2 = [0.2, 0.3, 0.4]185    ms.add_feature_floats(values_1, example, "1")186    ms.add_feature_floats(values_1, example, "1")187    ms.add_feature_floats(values_2, example, "2")188    self.assertEqual(2, ms.get_feature_floats_size(example, "1"))189    self.assertEqual(1, ms.get_feature_floats_size(example, "2"))190    self.assertTrue(ms.has_feature_floats(example, "1"))191    self.assertTrue(ms.has_feature_floats(example, "2"))192    self.assertAllClose(values_1, ms.get_feature_floats_at(0, example, "1"))193    self.assertAllClose(values_2, ms.get_feature_floats_at(0, example, "2"))194    ms.clear_feature_floats(example, "1")195    self.assertEqual(0, ms.get_feature_floats_size(example, "1"))196    self.assertFalse(ms.has_feature_floats(example, "1"))197    self.assertEqual(1, ms.get_feature_floats_size(example, "2"))198    self.assertTrue(ms.has_feature_floats(example, "2"))199    ms.clear_feature_floats(example, "2")200    self.assertEqual(0, ms.get_feature_floats_size(example, "2"))201    self.assertFalse(ms.has_feature_floats(example, "2"))202  def test_feature_timestamp_round_trip(self):203    example = tf.train.SequenceExample()204    values_1 = 47205    values_2 = 49206    ms.add_feature_timestamp(values_1, example, "1")207    ms.add_feature_timestamp(values_1, example, "1")208    ms.add_feature_timestamp(values_2, example, "2")209    self.assertEqual(2, ms.get_feature_timestamp_size(example, "1"))210    self.assertEqual(1, ms.get_feature_timestamp_size(example, "2"))211    self.assertTrue(ms.has_feature_timestamp(example, "1"))212    self.assertTrue(ms.has_feature_timestamp(example, "2"))213    self.assertAllClose(values_1,214                        ms.get_feature_timestamp_at(0, example, "1"))215    self.assertAllClose(values_2,216                        ms.get_feature_timestamp_at(0, example, "2"))217    ms.clear_feature_timestamp(example, "1")218    self.assertEqual(0, ms.get_feature_timestamp_size(example, "1"))219    self.assertFalse(ms.has_feature_timestamp(example, "1"))220    self.assertEqual(1, ms.get_feature_timestamp_size(example, "2"))221    self.assertTrue(ms.has_feature_timestamp(example, "2"))222    ms.clear_feature_timestamp(example, "2")223    self.assertEqual(0, ms.get_feature_timestamp_size(example, "2"))224    self.assertFalse(ms.has_feature_timestamp(example, "2"))225  def test_feature_dimensions_round_trip(self):226    example = tf.train.SequenceExample()227    ms.set_feature_dimensions([47, 49], example, "1")228    ms.set_feature_dimensions([49, 50], example, "2")229    self.assertSequenceEqual([47, 49],230                             ms.get_feature_dimensions(example, "1"))231    self.assertSequenceEqual([49, 50],232                             ms.get_feature_dimensions(example, "2"))233    self.assertTrue(ms.has_feature_dimensions(example, "1"))234    self.assertTrue(ms.has_feature_dimensions(example, "2"))235    ms.clear_feature_dimensions(example, "1")236    self.assertFalse(ms.has_feature_dimensions(example, "1"))237    self.assertTrue(ms.has_feature_dimensions(example, "2"))238    ms.clear_feature_dimensions(example, "2")239    self.assertFalse(ms.has_feature_dimensions(example, "1"))240    self.assertFalse(ms.has_feature_dimensions(example, "2"))...RNTesterList.ios.js
Source:RNTesterList.ios.js  
1/**2 * Copyright (c) Meta Platforms, Inc. and affiliates.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 *7 * @format8 * @flow9 */10'use strict';11import type {RNTesterModuleInfo} from '../types/RNTesterTypes';12const Components: Array<RNTesterModuleInfo> = [13  {14    key: 'ActivityIndicatorExample',15    category: 'UI',16    module: require('../examples/ActivityIndicator/ActivityIndicatorExample'),17    supportsTVOS: true,18  },19  {20    key: 'ButtonExample',21    module: require('../examples/Button/ButtonExample'),22    category: 'UI',23    supportsTVOS: true,24  },25  {26    key: 'FlatListExampleIndex',27    module: require('../examples/FlatList/FlatListExampleIndex').default,28    category: 'ListView',29    supportsTVOS: true,30  },31  {32    key: 'ImageExample',33    module: require('../examples/Image/ImageExample'),34    category: 'Basic',35    supportsTVOS: true,36  },37  {38    key: 'JSResponderHandlerExample',39    module: require('../examples/JSResponderHandlerExample/JSResponderHandlerExample'),40  },41  {42    key: 'InputAccessoryViewExample',43    module: require('../examples/InputAccessoryView/InputAccessoryViewExample'),44    supportsTVOS: false,45  },46  {47    key: 'KeyboardAvoidingViewExample',48    module: require('../examples/KeyboardAvoidingView/KeyboardAvoidingViewExample'),49    supportsTVOS: false,50  },51  {52    key: 'LayoutEventsExample',53    module: require('../examples/Layout/LayoutEventsExample'),54    supportsTVOS: true,55  },56  {57    key: 'ModalExample',58    module: require('../examples/Modal/ModalExample'),59    supportsTVOS: true,60  },61  {62    key: 'NewAppScreenExample',63    module: require('../examples/NewAppScreen/NewAppScreenExample'),64    supportsTVOS: false,65  },66  {67    key: 'PressableExample',68    module: require('../examples/Pressable/PressableExample'),69    supportsTVOS: true,70  },71  {72    key: 'RefreshControlExample',73    module: require('../examples/RefreshControl/RefreshControlExample'),74    supportsTVOS: false,75  },76  {77    key: 'ScrollViewSimpleExample',78    module: require('../examples/ScrollView/ScrollViewSimpleExample'),79    category: 'Basic',80    supportsTVOS: true,81  },82  {83    key: 'SafeAreaViewExample',84    module: require('../examples/SafeAreaView/SafeAreaViewExample'),85    supportsTVOS: false,86  },87  {88    key: 'ScrollViewExample',89    module: require('../examples/ScrollView/ScrollViewExample'),90    category: 'Basic',91    supportsTVOS: true,92  },93  {94    key: 'ScrollViewAnimatedExample',95    module: require('../examples/ScrollView/ScrollViewAnimatedExample'),96    supportsTVOS: true,97  },98  {99    key: 'ScrollViewIndicatorInsetsExample',100    module: require('../examples/ScrollView/ScrollViewIndicatorInsetsExample'),101    supportsTVOS: true,102  },103  {104    key: 'SectionListIndex',105    module: require('../examples/SectionList/SectionListIndex'),106    supportsTVOS: true,107  },108  {109    key: 'TVTextScrollViewExample',110    module: require('../examples/TVTextScrollView/TVTextScrollViewExample'),111    supportsTVOS: true,112  },113  {114    key: 'StatusBarExample',115    module: require('../examples/StatusBar/StatusBarExample'),116    supportsTVOS: false,117  },118  {119    key: 'SwipeableCardExample',120    module: require('../examples/SwipeableCardExample/SwipeableCardExample'),121    category: 'UI',122    supportsTVOS: false,123  },124  {125    key: 'SwitchExample',126    module: require('../examples/Switch/SwitchExample'),127    category: 'UI',128    supportsTVOS: false,129  },130  {131    key: 'TextExample',132    module: require('../examples/Text/TextExample.ios'),133    category: 'Basic',134    supportsTVOS: true,135  },136  {137    key: 'TextInputExample',138    module: require('../examples/TextInput/TextInputExample'),139    category: 'Basic',140    supportsTVOS: true,141  },142  {143    key: 'TouchableExample',144    module: require('../examples/Touchable/TouchableExample'),145    supportsTVOS: true,146  },147  {148    key: 'TransparentHitTestExample',149    module: require('../examples/TransparentHitTest/TransparentHitTestExample'),150    supportsTVOS: false,151  },152  {153    key: 'ViewExample',154    module: require('../examples/View/ViewExample'),155    category: 'Basic',156    supportsTVOS: true,157  },158  {159    key: 'NewArchitectureExample',160    category: 'UI',161    module: require('../examples/NewArchitecture/NewArchitectureExample'),162    supportsTVOS: false,163  },164];165const APIs: Array<RNTesterModuleInfo> = [166  {167    key: 'AccessibilityExample',168    module: require('../examples/Accessibility/AccessibilityExample'),169    supportsTVOS: false,170  },171  {172    key: 'AccessibilityIOSExample',173    module: require('../examples/Accessibility/AccessibilityIOSExample'),174    category: 'iOS',175    supportsTVOS: false,176  },177  {178    key: 'ActionSheetIOSExample',179    module: require('../examples/ActionSheetIOS/ActionSheetIOSExample'),180    category: 'iOS',181    supportsTVOS: true,182  },183  {184    key: 'AlertIOSExample',185    module: require('../examples/Alert/AlertIOSExample'),186    category: 'iOS',187    supportsTVOS: true,188  },189  {190    key: 'AnimatedIndex',191    module: require('../examples/Animated/AnimatedIndex').default,192    supportsTVOS: true,193  },194  {195    key: 'AnExApp',196    module: require('../examples/AnimatedGratuitousApp/AnExApp'),197    supportsTVOS: true,198  },199  {200    key: 'AppearanceExample',201    module: require('../examples/Appearance/AppearanceExample'),202    supportsTVOS: false,203  },204  {205    key: 'AppStateExample',206    module: require('../examples/AppState/AppStateExample'),207    supportsTVOS: true,208  },209  {210    key: 'BorderExample',211    module: require('../examples/Border/BorderExample'),212    supportsTVOS: true,213  },214  {215    key: 'BoxShadowExample',216    module: require('../examples/BoxShadow/BoxShadowExample'),217    supportsTVOS: true,218  },219  {220    key: 'CrashExample',221    module: require('../examples/Crash/CrashExample'),222    supportsTVOS: false,223  },224  {225    key: 'DevSettings',226    module: require('../examples/DevSettings/DevSettingsExample'),227  },228  {229    key: 'Dimensions',230    module: require('../examples/Dimensions/DimensionsExample'),231    supportsTVOS: true,232  },233  {234    key: 'LayoutAnimationExample',235    module: require('../examples/Layout/LayoutAnimationExample'),236    supportsTVOS: true,237  },238  {239    key: 'LayoutExample',240    module: require('../examples/Layout/LayoutExample'),241    supportsTVOS: true,242  },243  {244    key: 'LinkingExample',245    module: require('../examples/Linking/LinkingExample'),246    supportsTVOS: true,247  },248  {249    key: 'NativeAnimationsExample',250    module: require('../examples/NativeAnimation/NativeAnimationsExample'),251    supportsTVOS: true,252  },253  {254    key: 'OrientationChangeExample',255    module: require('../examples/OrientationChange/OrientationChangeExample'),256    supportsTVOS: false,257  },258  {259    key: 'PanResponderExample',260    module: require('../examples/PanResponder/PanResponderExample'),261    supportsTVOS: false,262  },263  {264    key: 'PlatformColorExample',265    module: require('../examples/PlatformColor/PlatformColorExample'),266    supportsTVOS: true,267  },268  {269    key: 'PointerEventsExample',270    module: require('../examples/PointerEvents/PointerEventsExample'),271    supportsTVOS: false,272  },273  {274    key: 'RCTRootViewIOSExample',275    module: require('../examples/RCTRootView/RCTRootViewIOSExample'),276    supportsTVOS: true,277  },278  {279    key: 'RTLExample',280    module: require('../examples/RTL/RTLExample'),281    supportsTVOS: true,282  },283  {284    key: 'ShareExample',285    module: require('../examples/Share/ShareExample'),286    supportsTVOS: true,287  },288  {289    key: 'SnapshotExample',290    module: require('../examples/Snapshot/SnapshotExample'),291    supportsTVOS: true,292  },293  {294    key: 'TimerExample',295    module: require('../examples/Timer/TimerExample'),296    supportsTVOS: true,297  },298  {299    key: 'TransformExample',300    module: require('../examples/Transform/TransformExample'),301    supportsTVOS: true,302  },303  {304    key: 'TVEventHandlerExample',305    category: 'TV',306    module: require('../examples/TVEventHandler/TVEventHandlerExample'),307    supportsTVOS: true,308  },309  {310    key: 'TVDirectionalNextFocusExample',311    category: 'TV',312    module: require('../examples/DirectionalNextFocus/DirectionalNextFocusExample'),313    supportsTVOS: true,314  },315  {316    key: 'TVFocusGuideExample',317    category: 'TV',318    module: require('../examples/TVFocusGuide/TVFocusGuideExample'),319    supportsTVOS: true,320  },321  {322    key: 'TVFocusGuideSafePaddingExample',323    category: 'TV',324    module: require('../examples/TVFocusGuide/TVFocusGuideSafePaddingExample'),325    supportsTVOS: true,326  },327  {328    key: 'TurboModuleExample',329    module: require('../examples/TurboModule/TurboModuleExample'),330    supportsTVOS: false,331  },332  {333    key: 'VibrationExample',334    module: require('../examples/Vibration/VibrationExample'),335    supportsTVOS: false,336  },337  {338    key: 'WebSocketExample',339    module: require('../examples/WebSocket/WebSocketExample'),340    supportsTVOS: true,341  },342  {343    key: 'XHRExample',344    module: require('../examples/XHR/XHRExample'),345    supportsTVOS: true,346  },347];348const Modules: {...} = {};349APIs.concat(Components).forEach(Example => {350  Modules[Example.key] = Example.module;351});352const RNTesterList = {353  APIs,354  Components,355  Modules,356};...RNTesterList.android.js
Source:RNTesterList.android.js  
1/**2 * Copyright (c) Meta Platforms, Inc. and affiliates.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 *7 * @format8 * @flow9 */10'use strict';11import type {RNTesterModuleInfo} from '../types/RNTesterTypes';12const Components: Array<RNTesterModuleInfo> = [13  {14    key: 'ActivityIndicatorExample',15    category: 'UI',16    module: require('../examples/ActivityIndicator/ActivityIndicatorExample'),17  },18  {19    key: 'ButtonExample',20    category: 'UI',21    module: require('../examples/Button/ButtonExample'),22  },23  {24    key: 'FlatListExampleIndex',25    module: require('../examples/FlatList/FlatListExampleIndex').default,26    category: 'ListView',27    supportsTVOS: true,28  },29  {30    key: 'ImageExample',31    category: 'Basic',32    module: require('../examples/Image/ImageExample'),33  },34  {35    key: 'JSResponderHandlerExample',36    module: require('../examples/JSResponderHandlerExample/JSResponderHandlerExample'),37  },38  {39    key: 'KeyboardAvoidingViewExample',40    module: require('../examples/KeyboardAvoidingView/KeyboardAvoidingViewExample'),41  },42  {43    key: 'ModalExample',44    category: 'UI',45    module: require('../examples/Modal/ModalExample'),46  },47  {48    key: 'NewAppScreenExample',49    module: require('../examples/NewAppScreen/NewAppScreenExample'),50  },51  {52    key: 'PressableExample',53    category: 'UI',54    module: require('../examples/Pressable/PressableExample'),55  },56  {57    key: 'RefreshControlExample',58    module: require('../examples/RefreshControl/RefreshControlExample'),59  },60  {61    key: 'ScrollViewExample',62    category: 'Basic',63    module: require('../examples/ScrollView/ScrollViewExample'),64  },65  {66    key: 'ScrollViewSimpleExample',67    category: 'Basic',68    module: require('../examples/ScrollView/ScrollViewSimpleExample'),69  },70  {71    key: 'ScrollViewAnimatedExample',72    category: 'Basic',73    module: require('../examples/ScrollView/ScrollViewAnimatedExample'),74  },75  {76    key: 'TVTextScrollViewExample',77    module: require('../examples/TVTextScrollView/TVTextScrollViewExample'),78  },79  {80    key: 'SectionListExample',81    category: 'ListView',82    module: require('../examples/SectionList/SectionListIndex'),83  },84  {85    key: 'StatusBarExample',86    category: 'UI',87    module: require('../examples/StatusBar/StatusBarExample'),88  },89  {90    key: 'SwipeableCardExample',91    category: 'UI',92    module: require('../examples/SwipeableCardExample/SwipeableCardExample'),93  },94  {95    key: 'SwitchExample',96    category: 'UI',97    module: require('../examples/Switch/SwitchExample'),98  },99  {100    key: 'TextExample',101    category: 'Basic',102    module: require('../examples/Text/TextExample'),103  },104  {105    key: 'TextInputExample',106    category: 'Basic',107    module: require('../examples/TextInput/TextInputExample'),108  },109  {110    key: 'TextInputs with key prop',111    module: require('../examples/TextInput/TextInputKeyProp'),112  },113  {114    key: 'TouchableExample',115    category: 'UI',116    module: require('../examples/Touchable/TouchableExample'),117  },118  {119    key: 'ViewExample',120    category: 'Basic',121    module: require('../examples/View/ViewExample'),122  },123  {124    key: 'NewArchitectureExample',125    category: 'UI',126    module: require('../examples/NewArchitecture/NewArchitectureExample'),127  },128];129const APIs: Array<RNTesterModuleInfo> = [130  {131    key: 'AccessibilityExample',132    category: 'Basic',133    module: require('../examples/Accessibility/AccessibilityExample'),134  },135  {136    key: 'AccessibilityAndroidExample',137    category: 'Android',138    module: require('../examples/Accessibility/AccessibilityAndroidExample'),139  },140  {141    key: 'AlertExample',142    category: 'UI',143    module: require('../examples/Alert/AlertExample'),144  },145  {146    key: 'AnimatedIndex',147    category: 'UI',148    module: require('../examples/Animated/AnimatedIndex').default,149  },150  {151    key: 'Animation - GratuitousAnimation',152    category: 'UI',153    module: require('../examples/AnimatedGratuitousApp/AnExApp'),154  },155  {156    key: 'AppearanceExample',157    category: 'UI',158    module: require('../examples/Appearance/AppearanceExample'),159  },160  {161    key: 'AppStateExample',162    category: 'Basic',163    module: require('../examples/AppState/AppStateExample'),164  },165  {166    key: 'BorderExample',167    category: 'UI',168    module: require('../examples/Border/BorderExample'),169  },170  {171    key: 'CrashExample',172    category: 'Basic',173    module: require('../examples/Crash/CrashExample'),174  },175  {176    key: 'DevSettings',177    category: 'Basic',178    module: require('../examples/DevSettings/DevSettingsExample'),179  },180  {181    key: 'Dimensions',182    category: 'UI',183    module: require('../examples/Dimensions/DimensionsExample'),184  },185  {186    key: 'LayoutEventsExample',187    category: 'UI',188    module: require('../examples/Layout/LayoutEventsExample'),189  },190  {191    key: 'LinkingExample',192    category: 'Basic',193    module: require('../examples/Linking/LinkingExample'),194  },195  {196    key: 'LayoutAnimationExample',197    category: 'UI',198    module: require('../examples/Layout/LayoutAnimationExample'),199  },200  {201    key: 'LayoutExample',202    category: 'UI',203    module: require('../examples/Layout/LayoutExample'),204  },205  {206    key: 'NativeAnimationsExample',207    category: 'UI',208    module: require('../examples/NativeAnimation/NativeAnimationsExample'),209  },210  {211    key: 'OrientationChangeExample',212    category: 'UI',213    module: require('../examples/OrientationChange/OrientationChangeExample'),214  },215  {216    key: 'PanResponderExample',217    category: 'Basic',218    module: require('../examples/PanResponder/PanResponderExample'),219  },220  {221    key: 'PermissionsExampleAndroid',222    category: 'Android',223    module: require('../examples/PermissionsAndroid/PermissionsExample'),224  },225  {226    key: 'PlatformColorExample',227    category: 'UI',228    module: require('../examples/PlatformColor/PlatformColorExample'),229  },230  {231    key: 'PointerEventsExample',232    category: 'Basic',233    module: require('../examples/PointerEvents/PointerEventsExample'),234  },235  {236    key: 'RTLExample',237    category: 'Basic',238    module: require('../examples/RTL/RTLExample'),239  },240  {241    key: 'ShareExample',242    category: 'Basic',243    module: require('../examples/Share/ShareExample'),244  },245  {246    key: 'TimerExample',247    category: 'UI',248    module: require('../examples/Timer/TimerExample'),249  },250  {251    key: 'ToastAndroidExample',252    category: 'Android',253    module: require('../examples/ToastAndroid/ToastAndroidExample'),254  },255  {256    key: 'TransformExample',257    category: 'UI',258    module: require('../examples/Transform/TransformExample'),259  },260  {261    key: 'TVEventHandlerExample',262    module: require('../examples/TVEventHandler/TVEventHandlerExample'),263  },264  {265    key: 'DirectionalNextFocusExample',266    module: require('../examples/DirectionalNextFocus/DirectionalNextFocusExample'),267  },268  {269    key: 'TVFocusGuideExample',270    module: require('../examples/TVFocusGuide/TVFocusGuideExample'),271  },272  {273    key: 'TVFocusGuideSafePaddingExample',274    module: require('../examples/TVFocusGuide/TVFocusGuideSafePaddingExample'),275  },276  {277    key: 'VibrationExample',278    category: 'Basic',279    module: require('../examples/Vibration/VibrationExample'),280  },281  {282    key: 'WebSocketExample',283    category: 'Basic',284    module: require('../examples/WebSocket/WebSocketExample'),285  },286  {287    key: 'XHRExample',288    category: 'Basic',289    module: require('../examples/XHR/XHRExample'),290  },291];292if (global.__turboModuleProxy) {293  APIs.push({294    key: 'TurboModuleExample',295    category: 'Basic',296    module: require('../examples/TurboModule/TurboModuleExample'),297  });298}299const Modules: any = {};300APIs.concat(Components).forEach(Example => {301  Modules[Example.key] = Example.module;302});303const RNTesterList = {304  APIs,305  Components,306  Modules,307};...2746-stable-sort.js
Source:2746-stable-sort.js  
1// DATA_TEMPLATE: dom_data2oTest.fnStart( "2746 - Stable sorting" );3$(document).ready( function () {4	$('#example').dataTable();5	6	oTest.fnTest( 7		"Initial sort",8		null,9		function () {10			var ret =11				$('#example tbody tr:eq(0) td:eq(0)').html() == 'Gecko' &&12				$('#example tbody tr:eq(1) td:eq(0)').html() == 'Gecko' &&13				$('#example tbody tr:eq(0) td:eq(1)').html() == 'Firefox 1.0' &&14				$('#example tbody tr:eq(1) td:eq(1)').html() == 'Firefox 1.5' &&15				$('#example tbody tr:eq(2) td:eq(1)').html() == 'Firefox 2.0';16			return ret;17		}18	);19	20	oTest.fnTest( 21		"Reserve initial sort",22		function () {23			$('#example thead th:eq(0)').click();24		},25		function () {26			var ret =27				$('#example tbody tr:eq(0) td:eq(0)').html() == 'Webkit' &&28				$('#example tbody tr:eq(1) td:eq(0)').html() == 'Webkit' &&29				$('#example tbody tr:eq(0) td:eq(1)').html() == 'Safari 1.2' &&30				$('#example tbody tr:eq(1) td:eq(1)').html() == 'Safari 1.3' &&31				$('#example tbody tr:eq(2) td:eq(1)').html() == 'Safari 2.0';32			return ret;33		}34	);35	36	oTest.fnTest( 37		"Reserve to go back to initial sort sort",38		function () {39			$('#example thead th:eq(0)').click();40		},41		function () {42			var ret =43				$('#example tbody tr:eq(0) td:eq(0)').html() == 'Gecko' &&44				$('#example tbody tr:eq(1) td:eq(0)').html() == 'Gecko' &&45				$('#example tbody tr:eq(0) td:eq(1)').html() == 'Firefox 1.0' &&46				$('#example tbody tr:eq(1) td:eq(1)').html() == 'Firefox 1.5' &&47				$('#example tbody tr:eq(2) td:eq(1)').html() == 'Firefox 2.0';48			return ret;49		}50	);51	52	oTest.fnTest( 53		"Reserve initial sort again",54		function () {55			$('#example thead th:eq(0)').click();56		},57		function () {58			var ret =59				$('#example tbody tr:eq(0) td:eq(0)').html() == 'Webkit' &&60				$('#example tbody tr:eq(1) td:eq(0)').html() == 'Webkit' &&61				$('#example tbody tr:eq(0) td:eq(1)').html() == 'Safari 1.2' &&62				$('#example tbody tr:eq(1) td:eq(1)').html() == 'Safari 1.3' &&63				$('#example tbody tr:eq(2) td:eq(1)').html() == 'Safari 2.0';64			return ret;65		}66	);67	68	oTest.fnTest( 69		"And once more back to the initial sort",70		function () {71			$('#example thead th:eq(0)').click();72		},73		function () {74			var ret =75				$('#example tbody tr:eq(0) td:eq(0)').html() == 'Gecko' &&76				$('#example tbody tr:eq(1) td:eq(0)').html() == 'Gecko' &&77				$('#example tbody tr:eq(0) td:eq(1)').html() == 'Firefox 1.0' &&78				$('#example tbody tr:eq(1) td:eq(1)').html() == 'Firefox 1.5' &&79				$('#example tbody tr:eq(2) td:eq(1)').html() == 'Firefox 2.0';80			return ret;81		}82	);83	84	oTest.fnTest( 85		"Sort on second column",86		function () {87			$('#example thead th:eq(1)').click();88		},89		function () {90			var ret =91				$('#example tbody tr:eq(0) td:eq(0)').html() == 'Other browsers' &&92				$('#example tbody tr:eq(1) td:eq(0)').html() == 'Trident' &&93				$('#example tbody tr:eq(0) td:eq(1)').html() == 'All others' &&94				$('#example tbody tr:eq(1) td:eq(1)').html() == 'AOL browser (AOL desktop)' &&95				$('#example tbody tr:eq(2) td:eq(1)').html() == 'Camino 1.0';96			return ret;97		}98	);99	100	oTest.fnTest( 101		"Reserve sort on second column",102		function () {103			$('#example thead th:eq(1)').click();104		},105		function () {106			var ret =107				$('#example tbody tr:eq(0) td:eq(0)').html() == 'Gecko' &&108				$('#example tbody tr:eq(1) td:eq(0)').html() == 'Webkit' &&109				$('#example tbody tr:eq(0) td:eq(1)').html() == 'Seamonkey 1.1' &&110				$('#example tbody tr:eq(1) td:eq(1)').html() == 'Safari 3.0' &&111				$('#example tbody tr:eq(2) td:eq(1)').html() == 'Safari 2.0';112			return ret;113		}114	);115	116	oTest.fnTest( 117		"And back to asc sorting on second column",118		function () {119			$('#example thead th:eq(1)').click();120		},121		function () {122			var ret =123				$('#example tbody tr:eq(0) td:eq(0)').html() == 'Other browsers' &&124				$('#example tbody tr:eq(1) td:eq(0)').html() == 'Trident' &&125				$('#example tbody tr:eq(0) td:eq(1)').html() == 'All others' &&126				$('#example tbody tr:eq(1) td:eq(1)').html() == 'AOL browser (AOL desktop)' &&127				$('#example tbody tr:eq(2) td:eq(1)').html() == 'Camino 1.0';128			return ret;129		}130	);131	132	oTest.fnTest( 133		"Sort on third column, having now sorted on second",134		function () {135			$('#example thead th:eq(2)').click();136		},137		function () {138			var ret =139				$('#example tbody tr:eq(0) td:eq(0)').html() == 'Other browsers' &&140				$('#example tbody tr:eq(1) td:eq(0)').html() == 'Misc' &&141				$('#example tbody tr:eq(0) td:eq(1)').html() == 'All others' &&142				$('#example tbody tr:eq(1) td:eq(1)').html() == 'Dillo 0.8' &&143				$('#example tbody tr:eq(2) td:eq(1)').html() == 'NetFront 3.1';144			return ret;145		}146	);147	148	oTest.fnTest( 149		"Reserve sort on third column",150		function () {151			$('#example thead th:eq(2)').click();152		},153		function () {154			var ret =155				$('#example tbody tr:eq(0) td:eq(0)').html() == 'Misc' &&156				$('#example tbody tr:eq(1) td:eq(0)').html() == 'Trident' &&157				$('#example tbody tr:eq(0) td:eq(1)').html() == 'IE Mobile' &&158				$('#example tbody tr:eq(1) td:eq(1)').html() == 'Internet Explorer 7' &&159				$('#example tbody tr:eq(2) td:eq(1)').html() == 'AOL browser (AOL desktop)';160			return ret;161		}162	);163	164	oTest.fnTest( 165		"Return sorting on third column to asc",166		function () {167			$('#example thead th:eq(2)').click();168		},169		function () {170			var ret =171				$('#example tbody tr:eq(0) td:eq(0)').html() == 'Other browsers' &&172				$('#example tbody tr:eq(1) td:eq(0)').html() == 'Misc' &&173				$('#example tbody tr:eq(0) td:eq(1)').html() == 'All others' &&174				$('#example tbody tr:eq(1) td:eq(1)').html() == 'Dillo 0.8' &&175				$('#example tbody tr:eq(2) td:eq(1)').html() == 'NetFront 3.1';176			return ret;177		}178	);179	180	oTest.fnTest( 181		"Sort on first column having sorted on second then third columns",182		function () {183			$('#example thead th:eq(0)').click();184		},185		function () {186			var ret =187				$('#example tbody tr:eq(0) td:eq(0)').html() == 'Gecko' &&188				$('#example tbody tr:eq(1) td:eq(0)').html() == 'Gecko' &&189				$('#example tbody tr:eq(0) td:eq(1)').html() == 'Epiphany 2.20' &&190				$('#example tbody tr:eq(1) td:eq(1)').html() == 'Camino 1.0' &&191				$('#example tbody tr:eq(2) td:eq(1)').html() == 'Camino 1.5';192			return ret;193		}194	);195	196	197	oTest.fnComplete();...index.js
Source:index.js  
1import React from 'react';2import { PageTitle } from '../../layout-components';3import { ExampleWrapperSeamless } from '../../layout-components';4import Alert from '@material-ui/lab/Alert';5import MarketingHero1 from '../../example-components/MarketingHero/MarketingHero1';6import MarketingHero2 from '../../example-components/MarketingHero/MarketingHero2';7import MarketingHero3 from '../../example-components/MarketingHero/MarketingHero3';8import MarketingHero4 from '../../example-components/MarketingHero/MarketingHero4';9import MarketingHero5 from '../../example-components/MarketingHero/MarketingHero5';10import MarketingHero6 from '../../example-components/MarketingHero/MarketingHero6';11import MarketingHero7 from '../../example-components/MarketingHero/MarketingHero7';12import MarketingHero8 from '../../example-components/MarketingHero/MarketingHero8';13import MarketingHero9 from '../../example-components/MarketingHero/MarketingHero9';14import MarketingHero10 from '../../example-components/MarketingHero/MarketingHero10';15import MarketingHero11 from '../../example-components/MarketingHero/MarketingHero11';16import MarketingHero12 from '../../example-components/MarketingHero/MarketingHero12';17import MarketingHero13 from '../../example-components/MarketingHero/MarketingHero13';18import MarketingHero14 from '../../example-components/MarketingHero/MarketingHero14';19import MarketingHero15 from '../../example-components/MarketingHero/MarketingHero15';20import MarketingHero16 from '../../example-components/MarketingHero/MarketingHero16';21import MarketingHero17 from '../../example-components/MarketingHero/MarketingHero17';22import MarketingHero18 from '../../example-components/MarketingHero/MarketingHero18';23import MarketingHero19 from '../../example-components/MarketingHero/MarketingHero19';24import MarketingHero20 from '../../example-components/MarketingHero/MarketingHero20';25export default function MarketingHero() {26  return (27    <>28      <PageTitle29        titleHeading="Hero Sections"30        titleDescription="Build presentation or marketing websites using these wonderful UI Kit components."31      />32      <Alert33        className="alerts-alternate text-center p-3 mb-5"34        severity="warning">35        The hero sections are best viewed on a full width viewport, like we set36        up in the UI Kit example pages.37      </Alert>38      <ExampleWrapperSeamless>39        <MarketingHero1 />40      </ExampleWrapperSeamless>41      <ExampleWrapperSeamless>42        <MarketingHero2 />43      </ExampleWrapperSeamless>44      <ExampleWrapperSeamless>45        <MarketingHero3 />46      </ExampleWrapperSeamless>47      <ExampleWrapperSeamless>48        <MarketingHero4 />49      </ExampleWrapperSeamless>50      <ExampleWrapperSeamless>51        <MarketingHero5 />52      </ExampleWrapperSeamless>53      <ExampleWrapperSeamless>54        <MarketingHero6 />55      </ExampleWrapperSeamless>56      <ExampleWrapperSeamless>57        <MarketingHero7 />58      </ExampleWrapperSeamless>59      <ExampleWrapperSeamless>60        <MarketingHero8 />61      </ExampleWrapperSeamless>62      <ExampleWrapperSeamless>63        <MarketingHero9 />64      </ExampleWrapperSeamless>65      <ExampleWrapperSeamless>66        <MarketingHero10 />67      </ExampleWrapperSeamless>68      <ExampleWrapperSeamless>69        <MarketingHero11 />70      </ExampleWrapperSeamless>71      <ExampleWrapperSeamless>72        <MarketingHero12 />73      </ExampleWrapperSeamless>74      <ExampleWrapperSeamless>75        <MarketingHero13 />76      </ExampleWrapperSeamless>77      <ExampleWrapperSeamless>78        <MarketingHero14 />79      </ExampleWrapperSeamless>80      <ExampleWrapperSeamless>81        <MarketingHero15 />82      </ExampleWrapperSeamless>83      <ExampleWrapperSeamless>84        <MarketingHero16 />85      </ExampleWrapperSeamless>86      <ExampleWrapperSeamless>87        <MarketingHero17 />88      </ExampleWrapperSeamless>89      <ExampleWrapperSeamless>90        <MarketingHero18 />91      </ExampleWrapperSeamless>92      <ExampleWrapperSeamless>93        <MarketingHero19 />94      </ExampleWrapperSeamless>95      <ExampleWrapperSeamless>96        <MarketingHero20 />97      </ExampleWrapperSeamless>98    </>99  );...runme.js
Source:runme.js  
1var example = require("example");2// Try to set the values of some global variables3example.ivar   =  42;4example.svar   = -31000;5example.lvar   =  65537;6example.uivar  =  123456;7example.usvar  =  61000;8example.ulvar  =  654321;9example.scvar  =  -13;10example.ucvar  =  251;11example.cvar   =  "S";12example.fvar   =  3.14159;13example.dvar   =  2.1828;14example.strvar =  "Hello World";15example.iptrvar= example.new_int(37);16example.ptptr  = example.new_Point(37,42);17example.name   = "Bill";18// Now console.log out the values of the variables19console.log("Variables (values printed from Javascript)");20console.log("ivar      = " + example.ivar);21console.log("svar      = " + example.svar);22console.log("lvar      = " + example.lvar);23console.log("uivar     = " + example.uivar);24console.log("usvar     = " + example.usvar);25console.log("ulvar     = " + example.ulvar);26console.log("scvar     = " + example.scvar);27console.log("ucvar     = " + example.ucvar);28console.log("fvar      = " + example.fvar);29console.log("dvar      = " + example.dvar);30console.log("cvar      = " + example.cvar);31console.log("strvar    = " + example.strvar);32console.log("cstrvar   = " + example.cstrvar);33console.log("iptrvar   = " + example.iptrvar);34console.log("name      = " + example.name);35console.log("ptptr     = " + example.ptptr + ": " + example.Point_print(example.ptptr));36console.log("pt        = " + example.pt + ": " + example.Point_print(example.pt));37console.log("\nVariables (values printed from C)");38example.print_vars();39console.log("\nNow I'm going to try and modify some read only variables");40console.log("Tring to set 'path'");41try{42    example.path = "Whoa!";43    console.log("Hey, what's going on?!?! This shouldn't work");44}45catch(e){46    console.log("Good.");47}48console.log("Trying to set 'status'");49try{50    example.status = 0;51    console.log("Hey, what's going on?!?! This shouldn't work");52} catch(e){53    console.log("Good.");54}55console.log("\nI'm going to try and update a structure variable.");56example.pt = example.ptptr;57console.log("The new value is: ");58example.pt_print();...Using AI Code Generation
1import { Example } from 'storybook-root';2export default () => (3);4{5  "dependencies": {6  }7}8{9}10import { configure } from '@storybook/react';11function loadStories() {12  require('../test');13}14configure(loadStories, module);15import '@storybook/addon-actions/register';16import '@storybook/addon-links/register';17import '@storybook/addon-knobs/register';18module.exports = (baseConfig, env, defaultConfig) => {19  defaultConfig.module.rules.push({20    test: /\.(js|jsx)$/,21  });22  return defaultConfig;23};24{25}26{27}Using AI Code Generation
1import { Example } from 'storybook-root';2const test = () => {3  return <Example />;4};5export default test;6import { configure, addDecorator } from '@storybook/react';7import { withKnobs } from '@storybook/addon-knobs';8import { withA11y } from '@storybook/addon-a11y';9import { withInfo } from '@storybook/addon-info';10import { withTests } from '@storybook/addon-jest';11import { withConsole } from '@storybook/addon-console';12import results from '../.jest-test-results.json';13import 'storybook-root/dist/index.css';14const req = require.context('../src', true, /.stories.js$/);15function loadStories() {16  req.keys().forEach(filename => req(filename));17}18configure(loadStories, module);19const path = require('path');20module.exports = async ({ config, mode }) => {21  config.module.rules.push({22    include: path.resolve(__dirname, '../'),23  });24  config.module.rules.push({25    test: /\.(ts|tsx)$/,26      {27        loader: require.resolve('awesome-typescript-loader'),28      },29      {30        loader: require.resolve('react-docgen-typescript-loader'),31      },32  });33  config.resolve.extensions.push('.ts', '.tsx');34  return config;35};36import '@storybook/addon-actions/register';37import '@storybook/addon-links/register';38import '@storybook/addon-knobs/register';39import '@storybook/addon-a11y/register';40import '@storybook/addon-info/register';41import '@storybook/addon-jest/register';42import '@storybook/addon-console';43{Using AI Code Generation
1import { Example } from 'storybook-root'2Example()3export const Example = () => {4  console.log('This is an example method')5}6{7}8import { Example } from 'storybook-root'9Example()10export const Example = () => {11  console.log('This is an example method')12}13{14}15import { Example } from 'storybook-root'16Example()17export const Example = () => {18  console.log('This is an example method')19}20{21}22import { Example } from 'storybook-root'23Example()24export const Example = () => {25  console.log('This is an example method')26}27{28}29import { Example } from 'storybook-root'30Example()31export const Example = () => {32  console.log('This is an example method')33}34{Using AI Code Generation
1import {Example} from 'storybook-root';2import React from 'react';3import ReactDOM from 'react-dom';4ReactDOM.render(<Example />, document.getElementById('root'));5const merge = require('webpack-merge');6const path = require('path');7const common = require('./webpack.common.js');8module.exports = merge(common, {9  devServer: {10    contentBase: path.join(__dirname, 'dist'),11  }12});13const path = require('path');14const HtmlWebpackPlugin = require('html-webpack-plugin');15const CopyWebpackPlugin = require('copy-webpack-plugin');16module.exports = {17    new HtmlWebpackPlugin({18    }),19    new CopyWebpackPlugin([20      { from: 'src/assets', to: 'assets' }21  module: {22      {23      },24      {25        test: /\.(png|svg|jpg|gif)$/,26      }27  },28  resolve: {29    alias: {30      'storybook-root': path.resolve(__dirname, '../')31    }32  }33};34{35  "scripts": {36  },37  "devDependencies": {38  },39  "dependencies": {40  }41}Using AI Code Generation
1import { Example } from 'storybook-root'2Example()3import { configure } from '@storybook/react'4import 'storybook-root'5const path = require('path')6module.exports = ({ config }) => {7  config.resolve.modules.push(path.resolve(__dirname, '../'))8}9{10  "scripts": {11  },12  "devDependencies": {13  },14  "dependencies": {15  }16}17{18}19{20  "rules": {21    "import/no-extraneous-dependencies": 022  }23}Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
