load("//tools/lint:lint.bzl", "add_lint_tests")
load(
    "//tools/skylark:drake_cc.bzl",
    "drake_cc_googletest",
    "drake_cc_library",
    "drake_cc_package_library",
)

package(default_visibility = ["//visibility:private"])

drake_cc_package_library(
    name = "ad",
    visibility = ["//visibility:private"],
    deps = [
        ":auto_diff",
    ],
)

drake_cc_library(
    name = "auto_diff",
    srcs = [
        "internal/partials.cc",
        "internal/standard_operations.cc",
    ],
    hdrs = [
        "auto_diff.h",
        "internal/eigen_specializations.h",
        "internal/partials.h",
        "internal/standard_operations.h",
    ],
    deps = [
        "//common:essential",
    ],
)

drake_cc_googletest(
    name = "auto_diff_basic_test",
    deps = [
        ":auto_diff",
    ],
)

drake_cc_googletest(
    name = "matrix_test",
    deps = [
        ":auto_diff",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "partials_test",
    deps = [
        ":auto_diff",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_library(
    name = "standard_operations_test_h",
    testonly = True,
    hdrs = ["test/standard_operations_test.h"],
    visibility = [
        # TODO(jwnimmer-tri) Once drake/common/autodiffxd.h is finally deleted,
        # we can also delete its unit test and thus withdraw this visibility.
        "//common:__pkg__",
    ],
    deps = [
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "standard_operations_test",
    # The test is split into multiple source files to improve compilation time.
    srcs = [
        "test/standard_operations_abs2_test.cc",
        "test/standard_operations_abs_test.cc",
        "test/standard_operations_acos_test.cc",
        "test/standard_operations_add_test.cc",
        "test/standard_operations_asin_test.cc",
        "test/standard_operations_atan2_test.cc",
        "test/standard_operations_atan_test.cc",
        "test/standard_operations_cmp_test.cc",
        "test/standard_operations_cos_test.cc",
        "test/standard_operations_cosh_test.cc",
        "test/standard_operations_dec_test.cc",
        "test/standard_operations_div_test.cc",
        "test/standard_operations_exp_test.cc",
        "test/standard_operations_inc_test.cc",
        "test/standard_operations_integer_test.cc",
        "test/standard_operations_log_test.cc",
        "test/standard_operations_max_test.cc",
        "test/standard_operations_min_test.cc",
        "test/standard_operations_mul_test.cc",
        "test/standard_operations_pow_special_test.cc",
        "test/standard_operations_pow_test.cc",
        "test/standard_operations_sin_test.cc",
        "test/standard_operations_sinh_test.cc",
        "test/standard_operations_sqrt_test.cc",
        "test/standard_operations_stream_test.cc",
        "test/standard_operations_sub_test.cc",
        "test/standard_operations_tan_test.cc",
        "test/standard_operations_tanh_test.cc",
    ],
    copts = [
        # The test fixture at requires some configuration for the specific
        # autodiff class to be tested.
        "-DDRAKE_AUTODIFFXD_DUT=drake::ad::AutoDiff",
    ],
    shard_count = 16,
    deps = [
        ":auto_diff",
        ":standard_operations_test_h",
    ],
)

add_lint_tests()
