File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -198,4 +198,29 @@ mod test {
198
198
199
199
assert_eq ! ( Value :: BigNum ( BigNum :: from( 50 ) ) , global_campaign_budget) ;
200
200
}
201
+
202
+ #[ test]
203
+ fn test_output_from_channel ( ) {
204
+ use crate :: channel:: { Pricing , PricingBounds } ;
205
+ use crate :: util:: tests:: prep_db:: DUMMY_CHANNEL ;
206
+
207
+ let mut channel = DUMMY_CHANNEL . clone ( ) ;
208
+ channel. spec . pricing_bounds = Some ( PricingBounds {
209
+ impression : Some ( Pricing {
210
+ min : 1_000 . into ( ) ,
211
+ max : 2_000 . into ( ) ,
212
+ } ) ,
213
+ click : Some ( Pricing {
214
+ min : 3_000 . into ( ) ,
215
+ max : 4_000 . into ( ) ,
216
+ } ) ,
217
+ } ) ;
218
+
219
+ let output = Output :: from ( & channel) ;
220
+
221
+ assert_eq ! ( true , output. show) ;
222
+ assert_eq ! ( 1.0 , output. boost) ;
223
+ assert_eq ! ( Some ( & BigNum :: from( 1_000 ) ) , output. price. get( "IMPRESSION" ) ) ;
224
+ assert_eq ! ( Some ( & BigNum :: from( 3_000 ) ) , output. price. get( "CLICK" ) ) ;
225
+ }
201
226
}
Original file line number Diff line number Diff line change @@ -123,6 +123,10 @@ impl Function {
123
123
Self :: Get ( key. to_string ( ) )
124
124
}
125
125
126
+ pub fn new_set ( key : & str , eval : impl Into < Rule > ) -> Self {
127
+ Self :: Set ( key. to_string ( ) , Box :: new ( eval. into ( ) ) )
128
+ }
129
+
126
130
pub fn new_bn ( value : impl Into < Value > ) -> Self {
127
131
Self :: Bn ( value. into ( ) )
128
132
}
@@ -492,4 +496,34 @@ mod test {
492
496
assert_eq ! ( Err ( Error :: TypeError ) , rule. eval( & input, & mut output) ) ;
493
497
}
494
498
}
499
+
500
+ #[ test]
501
+ fn test_set_eval ( ) {
502
+ use crate :: channel:: { Pricing , PricingBounds } ;
503
+ use crate :: util:: tests:: prep_db:: DUMMY_CHANNEL ;
504
+
505
+ let mut channel = DUMMY_CHANNEL . clone ( ) ;
506
+ channel. spec . pricing_bounds = Some ( PricingBounds {
507
+ impression : Some ( Pricing {
508
+ min : 1_000 . into ( ) ,
509
+ max : 2_000 . into ( ) ,
510
+ } ) ,
511
+ click : Some ( Pricing {
512
+ min : 3_000 . into ( ) ,
513
+ max : 4_000 . into ( ) ,
514
+ } ) ,
515
+ } ) ;
516
+
517
+ let input = Input :: default ( ) ;
518
+ let mut output = Output :: from ( & channel) ;
519
+
520
+ assert_eq ! ( Some ( & BigNum :: from( 1_000 ) ) , output. price. get( "IMPRESSION" ) ) ;
521
+
522
+ let set_to = Value :: BigNum ( BigNum :: from ( 20 ) ) ;
523
+ let rule = Rule :: Function ( Function :: new_set ( "price.IMPRESSION" , set_to) ) ;
524
+
525
+ assert_eq ! ( Ok ( None ) , rule. eval( & input, & mut output) ) ;
526
+
527
+ assert_eq ! ( Some ( & BigNum :: from( 20 ) ) , output. price. get( "IMPRESSION" ) ) ;
528
+ }
495
529
}
You can’t perform that action at this time.
0 commit comments