@@ -651,64 +651,87 @@ describe('Unit', function () {
651651 describe ( 'json' , function ( ) {
652652 it ( 'toJSON' , function ( ) {
653653 assert . deepStrictEqual ( new Unit ( 5 , 'cm' ) . toJSON ( ) ,
654- { mathjs : 'Unit' , value : 5 , unit : 'cm' , fixPrefix : false } )
654+ { mathjs : 'Unit' , value : 5 , unit : 'cm' , fixPrefix : false , skipSimp : true } )
655655 assert . deepStrictEqual ( new Unit ( 5 , 'cm' ) . to ( 'mm' ) . toJSON ( ) ,
656- { mathjs : 'Unit' , value : 50 , unit : 'mm' , fixPrefix : true } )
656+ { mathjs : 'Unit' , value : 50 , unit : 'mm' , fixPrefix : true , skipSimp : true } )
657657 assert . deepStrictEqual ( new Unit ( 5 , 'kN' ) . to ( 'kg m s ^ -2' ) . toJSON ( ) ,
658- { mathjs : 'Unit' , value : 5000 , unit : '(kg m) / s^2' , fixPrefix : true } )
658+ { mathjs : 'Unit' , value : 5000 , unit : '(kg m) / s^2' , fixPrefix : true , skipSimp : true } )
659659 assert . deepStrictEqual ( new Unit ( math . fraction ( 0.375 ) , 'cm' ) . toJSON ( ) ,
660660 {
661661 mathjs : 'Unit' ,
662662 value : math . fraction ( 0.375 ) , // Note that value is not serialized at this point, that will be done by JSON.stringify
663663 unit : 'cm' ,
664- fixPrefix : false
664+ fixPrefix : false ,
665+ skipSimp : true
665666 } )
666667 approxDeepEqual ( new Unit ( math . complex ( 2 , 4 ) , 'g' ) . toJSON ( ) ,
667668 {
668669 mathjs : 'Unit' ,
669670 value : math . complex ( 2 , 4 ) ,
670671 unit : 'g' ,
671- fixPrefix : false
672+ fixPrefix : false ,
673+ skipSimp : true
674+ } )
675+
676+ assert . deepStrictEqual ( math . evaluate ( '2 kg * 3 in^2' ) . toJSON ( ) ,
677+ {
678+ mathjs : 'Unit' ,
679+ value : 6 ,
680+ unit : 'kg in^2' ,
681+ fixPrefix : false ,
682+ skipSimp : false
672683 } )
673684
674685 const str = JSON . stringify ( new Unit ( math . fraction ( 0.375 ) , 'cm' ) )
675- assert . deepStrictEqual ( str , '{"mathjs":"Unit","value":{"mathjs":"Fraction","n":"3","d":"8"},"unit":"cm","fixPrefix":false}' )
686+ assert . deepStrictEqual ( str , '{"mathjs":"Unit","value":{"mathjs":"Fraction","n":"3","d":"8"},"unit":"cm","fixPrefix":false,"skipSimp":true }' )
676687
677688 const cmpx = JSON . stringify ( new Unit ( math . complex ( 2 , 4 ) , 'g' ) )
678- assert . strictEqual ( cmpx , '{"mathjs":"Unit","value":{"mathjs":"Complex","re":2,"im":4},"unit":"g","fixPrefix":false}' )
689+ assert . strictEqual ( cmpx , '{"mathjs":"Unit","value":{"mathjs":"Complex","re":2,"im":4},"unit":"g","fixPrefix":false,"skipSimp":true }' )
679690 } )
680691
681692 it ( 'fromJSON' , function ( ) {
682693 const u1 = new Unit ( 5 , 'cm' )
683- const u2 = Unit . fromJSON ( { mathjs : 'Unit' , value : 5 , unit : 'cm' , fixPrefix : false } )
694+ const u2 = Unit . fromJSON ( { mathjs : 'Unit' , value : 5 , unit : 'cm' , fixPrefix : false , skipSimp : true } )
684695 assert . ok ( u2 instanceof Unit )
685696 assert . deepStrictEqual ( u2 , u1 )
686697
687698 const u3 = new Unit ( 5 , 'cm' ) . to ( 'mm' )
688- const u4 = Unit . fromJSON ( { mathjs : 'Unit' , value : 50 , unit : 'mm' , fixPrefix : true } )
699+ const u4 = Unit . fromJSON ( { mathjs : 'Unit' , value : 50 , unit : 'mm' , fixPrefix : true , skipSimp : true } )
689700 assert . ok ( u4 instanceof Unit )
690701 assert . deepStrictEqual ( u4 , u3 )
691702
692703 const u5 = new Unit ( 5 , 'kN' ) . to ( 'kg m/s^2' )
693- const u6 = Unit . fromJSON ( { mathjs : 'Unit' , value : 5000 , unit : 'kg m s^-2' , fixPrefix : true } )
704+ const u6 = Unit . fromJSON ( { mathjs : 'Unit' , value : 5000 , unit : 'kg m s^-2' , fixPrefix : true , skipSimp : true } )
694705 assert . ok ( u6 instanceof Unit )
695706 assert . deepStrictEqual ( u5 , u6 )
696707
697708 const u7 = Unit . fromJSON ( {
698709 mathjs : 'Unit' ,
699710 value : math . fraction ( 0.375 ) , // Note that value is already a Fraction at this point, that will be done by JSON.parse(str, reviver)
700711 unit : 'cm' ,
701- fixPrefix : false
712+ fixPrefix : false ,
713+ skipSimp : true
702714 } )
703715 assert . deepStrictEqual ( u7 , new Unit ( math . fraction ( 0.375 ) , 'cm' ) )
704716
705717 const u8 = Unit . fromJSON ( {
706718 mathjs : 'Unit' ,
707719 value : math . complex ( 2 , 4 ) ,
708720 unit : 'g' ,
709- fixPrefix : false
721+ fixPrefix : false ,
722+ skipSimp : true
710723 } )
711724 assert . deepStrictEqual ( u8 , new Unit ( math . complex ( 2 , 4 ) , 'g' ) )
725+
726+ const u9 = Unit . fromJSON ( {
727+ mathjs : 'Unit' ,
728+ value : 6 ,
729+ unit : 'kg in^2' ,
730+ fixPrefix : false ,
731+ skipSimp : false
732+ } )
733+ const u10 = math . evaluate ( '2 kg * 3 in^2' )
734+ assert . deepStrictEqual ( u9 , u10 )
712735 } )
713736
714737 it ( 'toJSON -> fromJSON should recover an "equal" unit' , function ( ) {
0 commit comments