
    biy                     Z    d Z ddlZddlZddlmZ ddlmZ  G d dej                        Z	y)a,  
Copyright 2013 Steven Diamond

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    N)DCPError)Variablec                   @    e Zd ZdZd	dZd	dZd	dZd	dZd	dZd	dZ	y)
TestObjectivesz2 Unit tests for the expression/expression module. Nc                 l    t        d      | _        t        dd      | _        t        d      | _        y )Nx)name   yz)r   r   r   r   selfs    V/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/tests/test_objectives.pysetUpzTestObjectives.setUp   s(    s#!#&s#    c                    t        j                  | j                        }| j                  t	        |      dt	        | j                        z         t        j                  d| j                  z        }| j                  t	        |      dt	        d| j                  z        z         t        j
                  | j                        }| j                  t	        |      dt	        | j                        z         t        j
                  d| j                  z        }| j                  t	        |      dt	        d| j                  z        z         y)z%Test string representations.
        zMinimize(%s)   zMaximize(%s)N)cpMinimizer   assertEqualreprMaximize)r   objs     r   test_strzTestObjectives.test_str    s     kk$&&!cNT$&&\$ABkk!DFF(#cNT!DFF(^$CDkk$&&!cNT$&&\$ABkk!DFF(#cNT!DFF(^$CDr   c                    | j                   | j                  z   }t        j                  |      }| j	                  t        |      d|j                         z         |j                  \  }}| j	                  t        |      d       | j                  t              5 }t        j                  | j                        j                   d d d        | j	                  t        j                        d       |j                         }| j                  t        |      t        |      u        | j	                  |j                   |j                          | j#                  |j                   |j                   u        |j                  t        j$                  | j                        g      }| j                  t        |      t        |      u        | j                  |j                   d   j                   d   | j                  u        y # 1 sw Y   >xY w)Nzminimize %sr   z2The 'minimize' objective must resolve to a scalar.args)r   r   r   r   r   strr	   canonical_formlenassertRaises	Exceptionr   	exceptioncopy
assertTruetyper   assertFalsesquarer   expr   new_objconstraintscmr$   s          r   test_minimizezTestObjectives.test_minimize.   s{   fftvvokk#S=388:#=>"11 	[)1-y) 	/RKK..	/R\\*M	O xxzT
d3i/0 	CHH-chh./xxbii/0x1T
d3i/0		!))!,67	/ 	/s   *H  H
c                 6   | j                   | j                  z   }t        j                  |      }| j	                  t        |      d|j                         z         |j                  \  }}| j	                  t        |      d       | j                  t              5 }t        j                  | j                        j                   d d d        | j	                  t        j                        d       |j                         }| j                  t        |      t        |      u        | j	                  |j                   |j                          | j#                  |j                   |j                   u        |j                  t        j$                  | j                          g      }| j                  t        |      t        |      u        | j                  |j                   d   j                   d   j                   d   | j                   u        y # 1 sw Y   LxY w)Nzmaximize %sr   z2The 'maximize' objective must resolve to a scalar.r   )r   r   r   r   r   r   r	   r   r    r!   r"   r   r#   r$   r%   r&   r   r'   r(   r)   s          r   test_maximizezTestObjectives.test_maximizeI   s   fftvvokk#S=388:#=>"11 	[)1-y) 	/RKK..	/R\\*M	O xxzT
d3i/0 	CHH-chh./xxryy001x2T
d3i/0		!))!,11!4>?	/ 	/s   *HHc                    | j                  t        j                  t        j                  | j                              j                         d       | j                  t        j                  t        j                  | j                               j                         d       | j                  t        j                  t        j                  | j                              j                         d       | j                  t        j                  t        j                  | j                               j                         d       y )NTF)r   r   r   norm_infr   is_dcpr   r   s    r   test_is_dcpzTestObjectives.test_is_dcpd   s    R[[%89@@BDIbkk$&&&9%9:AACUKR[[%89@@BEJbkk$&&&9%9:AACTJr   c                    | j                   dz  }| j                   dz  }d}t        j                  |      t        j                  |      z   j                         sJ t        j                  |       t        j                  |       z   j                         sJ | j                  t              5 }t        j                  |      t        j                  |       z    ddd       | j                  t        j                        d       t        j                  |      t        j                  |       z
  j                         sJ |t        j                  |      z  j                         sJ |t        j                  |       z  j                         sJ | t        j                  |       z  j                         sJ | t        j                  |       z  j                         sJ y# 1 sw Y   xY w)z Test adding objectives.
        r   Nz"Problem does not follow DCP rules.)
r   r   r   r3   r   r!   r   r   r   r#   )r   expr1expr2alphar-   s        r   test_add_problemsz TestObjectives.test_add_problemsk   s    	2 E"R[[%77??AAAUF#bkk5&&99AACCC x( 	5BKKeV!44	5R\\*,PQE"R[[%%88@@BBB bkk%((00222bkk5&))11333r{{E6**22444r{{E6**22444	5 	5s   .-G**G4)returnN)
__name__
__module____qualname____doc__r   r   r.   r0   r4   r:    r   r   r   r      s&    <$
E86@6K5r   r   )
r?   unittestcvxpyr   cvxpy.errorr   cvxpy.expressions.variabler   TestCaser   r@   r   r   <module>rF      s,         /o5X&& o5r   