# HG changeset patch
# User Alexandru Ghitza <aghitza@alum.mit.edu>
# Date 1239430054 -36000
# Node ID d8b83a10963a68d8f9b1d4c054740d5e250f3395
# Parent  470a0a0e9a2c89bdace62f0d5e2051c43f6b0747
trac 5747: improve doctest coverage for schemes/generic/ambient_space.py

diff -r 470a0a0e9a2c -r d8b83a10963a sage/schemes/generic/affine_space.py
--- a/sage/schemes/generic/affine_space.py	Sun Apr 05 23:49:53 2009 -0700
+++ b/sage/schemes/generic/affine_space.py	Sat Apr 11 16:07:34 2009 +1000
@@ -265,6 +265,44 @@
             v = self.gens()
         return '\\left(%s\\right)'%(", ".join([str(latex(f)) for f in v]))
 
+    def _check_satisfies_equations(self, v):
+        """
+        Return True if `v` defines a point on the scheme self; raise a
+        TypeError otherwise.
+
+        EXAMPLES::
+
+            sage: A = AffineSpace(3, ZZ)
+            sage: A._check_satisfies_equations([1, 1, 0])
+            True
+            sage: A._check_satisfies_equations((0, 1, 0))
+            True
+            sage: A._check_satisfies_equations([0, 0, 0])
+            True
+            sage: A._check_satisfies_equations([1, 2, 3, 4, 5])
+            Traceback (most recent call last):
+            ...
+            TypeError: The list v=[1, 2, 3, 4, 5] must have 3 components
+            sage: A._check_satisfies_equations([1/2, 1, 1])
+            Traceback (most recent call last):
+            ...
+            TypeError: The components of v=[1/2, 1, 1] must be elements of Integer Ring
+            sage: A._check_satisfies_equations(5)
+            Traceback (most recent call last):            
+            ...
+            TypeError: The argument v=5 must be a list or tuple
+        """
+        if not isinstance(v, (list, tuple)):
+            raise TypeError, 'The argument v=%s must be a list or tuple'%v
+        n = self.ngens()
+        if not len(v) == n:
+            raise TypeError, 'The list v=%s must have %s components'%(v, n)
+        R = self.base_ring()
+        from sage.structure.sequence import Sequence
+        if not Sequence(v).universe() == R:
+            raise TypeError, 'The components of v=%s must be elements of %s'%(v, R)
+        return True
+
     def __pow__(self, m):
         """
         EXAMPLES::
diff -r 470a0a0e9a2c -r d8b83a10963a sage/schemes/generic/ambient_space.py
--- a/sage/schemes/generic/ambient_space.py	Sun Apr 05 23:49:53 2009 -0700
+++ b/sage/schemes/generic/ambient_space.py	Sat Apr 11 16:07:34 2009 +1000
@@ -18,6 +18,20 @@
 import scheme
 
 def is_AmbientSpace(x):
+    """
+    Return True if `x` is an ambient space.
+
+    EXAMPLES::
+
+        sage: from sage.schemes.generic.ambient_space import is_AmbientSpace
+        sage: is_AmbientSpace(ProjectiveSpace(3, ZZ))
+        True
+        sage: is_AmbientSpace(AffineSpace(2, QQ))
+        True
+        sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
+        sage: is_AmbientSpace(P.subscheme([x+y+z]))
+        False
+    """
     return isinstance(x, AmbientSpace)
 
 class AmbientSpace(scheme.Scheme, ParentWithGens):
@@ -32,6 +46,12 @@
     -  ``R`` - ring
     """
     def __init__(self, n, R=ZZ):
+        """
+        TEST::
+
+            sage: from sage.schemes.generic.ambient_space import AmbientSpace
+            sage: A = AmbientSpace(5, ZZ)
+        """
         if not is_CommutativeRing(R):
             raise TypeError, "R (=%s) must be a commutative ring"%R
         n = Integer(n)
@@ -44,29 +64,98 @@
     # Derived classes must overload all of the following functions
     #######################################################################
     def __cmp__(self, right):
+        """
+        TEST::
+
+            sage: from sage.schemes.generic.ambient_space import AmbientSpace
+            sage: A = AmbientSpace(5, ZZ)
+            sage: A.__cmp__(ProjectiveSpace(2, QQ))
+            Traceback (most recent call last):
+            ...
+            NotImplementedError
+        """
         raise NotImplementedError
 
     def _constructor(self):
+        """
+        TEST::
+
+            sage: from sage.schemes.generic.ambient_space import AmbientSpace
+            sage: A = AmbientSpace(5, ZZ)
+            sage: A._constructor()
+            Traceback (most recent call last):
+            ...
+            NotImplementedError
+        """
         raise NotImplementedError
 
     def _latex_(self):
+        """
+        TEST::
+
+            sage: from sage.schemes.generic.ambient_space import AmbientSpace
+            sage: A = AmbientSpace(5, ZZ)
+            sage: A._latex_()
+            Traceback (most recent call last):
+            ...
+            NotImplementedError
+        """
         raise NotImplementedError
 
     def _repr_(self):
+        """
+        TEST::
+
+            sage: from sage.schemes.generic.ambient_space import AmbientSpace
+            sage: A = AmbientSpace(5, ZZ)
+            sage: A._repr_()
+            Traceback (most recent call last):
+            ...
+            NotImplementedError
+        """
         raise NotImplementedError
 
     def _repr_generic_point(self, coords=None):
+        """
+        TEST::
+
+            sage: from sage.schemes.generic.ambient_space import AmbientSpace
+            sage: A = AmbientSpace(5, ZZ)
+            sage: A._repr_generic_point([1, 2, 3, 4, 5])
+            Traceback (most recent call last):
+            ...
+            NotImplementedError
+        """
         raise NotImplementedError
 
     def _latex_generic_point(self, coords=None):
+        """
+        TEST::
+
+            sage: from sage.schemes.generic.ambient_space import AmbientSpace
+            sage: A = AmbientSpace(5, ZZ)
+            sage: A._latex_generic_point([1, 2, 3, 4, 5])
+            Traceback (most recent call last):
+            ...
+            NotImplementedError
+        """
         raise NotImplementedError
 
     def _check_satisfies_equations(self, v):
         """
         Verify that the coordinates of v define a point on this scheme, or
         raise a TypeError.
+
+        TEST::
+
+            sage: from sage.schemes.generic.ambient_space import AmbientSpace
+            sage: A = AmbientSpace(5, ZZ)
+            sage: A._check_satisfies_equations([1, 2, 3, 4, 5])
+            Traceback (most recent call last):
+            ...
+            NotImplementedError
         """
-        return True
+        raise NotImplementedError
 
     #######################################################################
     # End overloads
@@ -74,6 +163,23 @@
 
 
     def base_extend(self, S, check=True):
+        """
+        Return the base change of self to the ring `S`, via the natural
+        map from the base ring of self to `S`.
+
+        A ValueError is raised if there is no natural map between the
+        two rings.
+
+        EXAMPLES::
+
+            sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
+            sage: PQ = P.base_extend(QQ); PQ
+            Projective Space of dimension 2 over Rational Field
+            sage: PQ.base_extend(GF(5))
+            Traceback (most recent call last):
+            ...
+            ValueError: No natural map from the base ring (=Rational Field) to S (=Finite Field of size 5)
+        """
         if is_CommutativeRing(S):
             R = self.base_ring()
             if S == R:
@@ -86,9 +192,34 @@
             raise NotImplementedError
 
     def ambient_space(self):
+        """
+        Return the ambient space of the scheme self, in this case self
+        itself.
+
+        EXAMPLES::
+
+            sage: P = ProjectiveSpace(4, ZZ)
+            sage: P.ambient_space() is P
+            True
+
+            sage: A = AffineSpace(2, GF(3))
+            sage: A.ambient_space()
+            Affine Space of dimension 2 over Finite Field of size 3
+        """
         return self
 
     def defining_polynomials(self):
+        """
+        Return the defining polynomials of the scheme self.  Since
+        self is an ambient space, this is an empty list.
+
+        EXAMPLES::
+
+            sage: ProjectiveSpace(2, QQ).defining_polynomials()
+            ()
+            sage: AffineSpace(0, ZZ).defining_polynomials()
+            ()
+        """
         return ()
     
     ######################################################################
@@ -96,13 +227,48 @@
     ######################################################################
     
     def gen(self, n=0):
+        """
+        Return the `n`-th generator of the coordinate ring of the
+        scheme self.
+
+        EXAMPLES::
+
+            sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
+            sage: P.gen(1)
+            y
+        """
         return self.coordinate_ring().gen(n)
 
     def gens(self):
+        """
+        Return the generators of the coordinate ring of the scheme
+        self.
+
+        EXAMPLES::
+
+            sage: AffineSpace(0, QQ).gens()
+            ()
+            
+            sage: P.<x, y, z> = ProjectiveSpace(2, GF(5))
+            sage: P.gens()
+            (x, y, z)
+        """
         return self.coordinate_ring().gens()
 
     def ngens(self):
-        raise NotImplementedError
+        """
+        Return the number of generators of the coordinate ring of the
+        scheme self.
+
+        EXAMPLES::
+
+            sage: AffineSpace(0, QQ).ngens()
+            0
+
+            sage: ProjectiveSpace(50, ZZ).ngens()
+            51
+        """
+        return len(self.gens())
 
 ##     def assign_names(self, names=None):
 ##         """
