license import * as tfOps from '@tensorflow/tfjs-core/dist/ops/ops_for_converter' ; import { ExecutionContext } from '../../executor/execution_context' ; import { Node } from '../types' ; import { executeOp } from './logical_executor' ; import { createTensorAttr } from './test_helper' ; describe ( 'logical' , ( ) => { let node ; const input1 = [ tfOps . scalar ( 1 ) ] ; const input2 = [ tfOps . scalar ( 2 ) ] ; const context = new ExecutionContext ( { } , { } , { } ) ; beforeEach ( ( ) => { node = { name : 'test' , op : '' , category : 'logical' , inputNames : [ 'input1' , 'input2' ] , inputs : [ ] , inputParams : { a : createTensorAttr ( 0 ) , b : createTensorAttr ( 1 ) } , attrParams : { } , children : [ ] } ; } ) ; describe ( 'executeOp' , ( ) => { [ 'Equal' , 'NotEqual' , 'Greater' , 'GreaterEqual' , 'Less' , 'LessEqual' , 'LogicalAnd' , 'LogicalOr' ] . forEach ( op => { it ( 'should call tfOps.' + op , ( ) => { const spy = spyOn ( tfOps , op . charAt ( 0 ) . toLowerCase ( ) + op . slice ( 1 ) as 'equal' ) ; node . op = op ; executeOp ( node , { input1 , input2 } , context ) ; expect ( spy ) . toHaveBeenCalledWith ( input1 [ 0 ] , input2 [ 0 ] ) ; } ) ; } ) ; describe ( 'LogicalNot' , ( ) => { it ( 'should call tfOps.logicalNot' , ( ) => { spyOn ( tfOps , 'logicalNot' ) ; node . op = 'LogicalNot' ; executeOp ( node , { input1 } , context ) ; expect ( tfOps . logicalNot ) . toHaveBeenCalledWith ( input1 [ 0 ] ) ; } ) ; } ) ; describe ( 'Select' , ( ) => { it ( 'should call tfOps.where' , ( ) => { spyOn ( tfOps , 'where' ) ; node . op = 'Select' ; node . inputNames = [ 'input1' , 'input2' , 'input3' ] ; node . inputParams . condition = createTensorAttr ( 2 ) ; const input3 = [ tfOps . scalar ( 1 ) ] ; executeOp ( node , { input1 , input2 , input3 } , context ) ; expect ( tfOps . where ) . toHaveBeenCalledWith ( input3 [ 0 ] , input1 [ 0 ] , input2 [ 0 ] ) ; } ) ; } ) ; describe ( 'SelectV2' , ( ) => { it ( 'should call tfOps.where' , ( ) => { spyOn ( tfOps , 'where' ) ; node . op = 'SelectV2' ; node . inputNames = [ 'input1' , 'input2' , 'input3' ] ; node . inputParams . condition = createTensorAttr ( 2 ) ; const input3 = [ tfOps . scalar ( 1 ) ] ; executeOp ( node , { input1 , input2 , input3 } , context ) ; expect ( tfOps . where ) . toHaveBeenCalledWith ( input3 [ 0 ] , input1 [ 0 ] , input2 [ 0 ] ) ; } ) ; } ) ; } ) ; } ) ;